官术网_书友最值得收藏!

Single-file components

A drawback of using components is that you need to write your template in a JavaScript string outside of your main HTML file. There are ways to write template definitions in your HTML file, but then you have an awkward separation between markup and logic.

A convenient solution to this issingle-file components:

<template>
  <li v-on:click="bought = !bought" v-bind:class="{ bought: bought }">
    <p>{{ title }}</p>
  </li>
</template>
<script> export default { props: [ 'title' ], data: function() { return { bought: false }; } } </script>
<style> .bought { opacity: 0.5; } </style>

These files have the.vueextension and encapsulate the component template, JavaScript configuration, and style all in a single file.

Of course, a web browser can't read these files, so they need to be first processed by a build tool such as Webpack.

主站蜘蛛池模板: 屏边| 博罗县| 修水县| 盱眙县| 台山市| 壤塘县| 澄城县| 视频| 新河县| 忻州市| 新建县| 黄冈市| 宁国市| 扶绥县| 南岸区| 含山县| 胶南市| 海兴县| 阳新县| 永清县| 靖安县| 玛纳斯县| 林西县| 湄潭县| 卓资县| 龙游县| 都匀市| 定西市| 岱山县| 丁青县| 仙居县| 阳谷县| 清镇市| 雷山县| 永泰县| 尤溪县| 南靖县| 常德市| 玉林市| 汾阳市| 藁城市|