- 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.
推薦閱讀
- 黑客攻防從入門到精通(實戰秘笈版)
- 玩轉Scratch少兒趣味編程
- FuelPHP Application Development Blueprints
- Java編程指南:基礎知識、類庫應用及案例設計
- 精通API架構:設計、運維與演進
- TypeScript實戰指南
- Mastering Drupal 8 Views
- Learning jQuery(Fourth Edition)
- Building Machine Learning Systems with Python(Second Edition)
- 軟件項目管理實用教程
- Python自然語言理解:自然語言理解系統開發與應用實戰
- Python趣味編程與精彩實例
- Python函數式編程(第2版)
- Python程序員面試算法寶典
- 數據結構案例教程:C語言版