- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 101字
- 2021-07-02 19:57:14
Components
Components extend basic HTML elements and allow you to create your own reusable custom elements.
For example, here I've created a custom element,grocery-item,which renders as ali. The text child of that node is sourced from a custom HTML property,title,which is accessible from within the component code:
<p id="app"> <h3>Grocery list</h3> <ul> <grocery-item title="Bread"></grocery-item> <grocery-item title="Milk"></grocery-item> </ul> </p> <script> Vue.component( 'grocery-item', { props: [ 'title' ], template: '<li>{{ title }}</li>' }); new Vue({ el: '#app' }); </script>
This renders as follows:
<p id="app"> <h3>Grocery list</h3> <ul> <li>Bread</li> <li>Milk</li> </ul> </p>
But probably the main reason to use components is that it makes it easier to architect a larger application. Functionality can be broken into reuseable, self-contained components.
推薦閱讀
- 深入理解Android(卷I)
- Java程序設計實戰教程
- Java 9 Concurrency Cookbook(Second Edition)
- Python數據分析基礎
- 算法訓練營:入門篇(全彩版)
- Java技術手冊(原書第7版)
- Learning Salesforce Einstein
- RISC-V體系結構編程與實踐(第2版)
- Visual Basic程序設計上機實驗教程
- Python深度學習原理、算法與案例
- Python程序設計教程
- INSTANT Lift Web Applications How-to
- 走近SDN/NFV
- ACE技術內幕:深入解析ACE架構設計與實現原理
- MongoDB進階與實戰:微服務整合、性能優化、架構管理