- 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.
推薦閱讀
- Google Apps Script for Beginners
- WildFly:New Features
- 程序員面試白皮書
- R語言數據可視化實戰
- Internet of Things with Intel Galileo
- Python 3破冰人工智能:從入門到實戰
- HTML5入門經典
- Mastering Apache Maven 3
- 軟件品質之完美管理:實戰經典
- Mastering Docker
- Mastering jQuery Mobile
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)
- Arduino Electronics Blueprints
- Python數據預處理技術與實踐
- Java Script從入門到精通(第5版)