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

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.

主站蜘蛛池模板: 当涂县| 玛纳斯县| 龙井市| 台北县| 和林格尔县| 阿拉善盟| 宜君县| 河津市| 襄樊市| 禹州市| 慈利县| 德昌县| 辰溪县| 焦作市| 绥宁县| 黔西县| 乐安县| 承德市| 青海省| 天全县| 洪洞县| 肥城市| 天气| 阜平县| 施秉县| 库伦旗| 石棉县| 麻阳| 河北区| 平武县| 大竹县| 南城县| 康乐县| 东乌珠穆沁旗| 池州市| 河北省| 恩施市| 湘乡市| 罗城| 呼和浩特市| 南投市|