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

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.

主站蜘蛛池模板: 宾川县| 藁城市| 巴楚县| 图木舒克市| 遂平县| 青河县| 社会| 祁门县| 铜梁县| 金川县| 河南省| 绥棱县| 岢岚县| 磴口县| 三江| 彭阳县| 黔江区| 武鸣县| 安丘市| 广汉市| 和平区| 天水市| 汶上县| 临洮县| 盐亭县| 辽阳县| 汉阴县| 乾安县| 庆阳市| 普格县| 沈阳市| 昌图县| 罗源县| 吉木乃县| 修武县| 米脂县| 兰考县| 龙陵县| 保亭| 新建县| 利津县|