- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 120字
- 2021-07-02 19:57:14
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.
推薦閱讀
- Expert C++
- Design Principles for Process:driven Architectures Using Oracle BPM and SOA Suite 12c
- SpringMVC+MyBatis快速開發(fā)與項(xiàng)目實(shí)戰(zhàn)
- Instant Zepto.js
- MySQL數(shù)據(jù)庫管理與開發(fā)實(shí)踐教程 (清華電腦學(xué)堂)
- Responsive Web Design by Example
- Visual C++開發(fā)入行真功夫
- 精通Python自動(dòng)化編程
- 零基礎(chǔ)學(xué)C語言第2版
- JavaScript+jQuery網(wǎng)頁特效設(shè)計(jì)任務(wù)驅(qū)動(dòng)教程
- SAP Web Dynpro for ABAP開發(fā)技術(shù)詳解:基礎(chǔ)應(yīng)用
- Microsoft HoloLens By Example
- Using Yocto Project with BeagleBone Black
- Mastering Magento Theme Design
- 走近SDN/NFV