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

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.

主站蜘蛛池模板: 株洲县| 东阳市| 县级市| 安达市| 宽甸| 堆龙德庆县| 乌什县| 天全县| 揭阳市| 莎车县| 昌黎县| 北碚区| 和政县| 古浪县| 且末县| 建德市| 奉化市| 垫江县| 河间市| 迁西县| 阿克| 汽车| 克山县| 营口市| 卢湾区| 宾川县| 潜江市| 武威市| 新营市| 深泽县| 当雄县| 固镇县| 鸡西市| 涪陵区| 丰顺县| 原阳县| 光山县| 盐池县| 华阴市| 沙雅县| 阳城县|