- 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.
推薦閱讀
- C/C++算法從菜鳥到達人
- Vue.js快跑:構建觸手可及的高性能Web應用
- Learning Laravel 4 Application Development
- Hands-On Enterprise Automation with Python.
- R大數據分析實用指南
- 數據結構案例教程(C/C++版)
- Mastering Business Intelligence with MicroStrategy
- Citrix XenServer企業運維實戰
- C++編程兵書
- Arduino計算機視覺編程
- 零代碼實戰:企業級應用搭建與案例詳解
- Scratch編程從入門到精通
- 你必須知道的.NET(第2版)
- 算法訓練營:海量圖解+競賽刷題(入門篇)
- Learning Ionic(Second Edition)