- 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.
推薦閱讀
- Mastering OpenLayers 3
- 微信小程序入門指南
- Oracle 18c 必須掌握的新特性:管理與實戰(zhàn)
- Kotlin從基礎(chǔ)到實戰(zhàn)
- Learning R for Geospatial Analysis
- Java Fundamentals
- ArcGIS for Desktop Cookbook
- Java 9 Programming By Example
- 現(xiàn)代C:概念剖析和編程實踐
- Drupal Search Engine Optimization
- Java EE項目應用開發(fā)
- 原型設(shè)計:打造成功產(chǎn)品的實用方法及實踐
- Manage Your SAP Projects with SAP Activate
- Learning NHibernate 4
- Python Django Web從入門到項目實戰(zhàn)(視頻版)