- 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.
推薦閱讀
- Web程序設(shè)計(jì)及應(yīng)用
- Java范例大全
- Mastering Adobe Captivate 2017(Fourth Edition)
- Python高效開發(fā)實(shí)戰(zhàn):Django、Tornado、Flask、Twisted(第2版)
- Java應(yīng)用開發(fā)技術(shù)實(shí)例教程
- 劍指MySQL:架構(gòu)、調(diào)優(yōu)與運(yùn)維
- Unity Game Development Scripting
- C#應(yīng)用程序設(shè)計(jì)教程
- Learning jQuery(Fourth Edition)
- Python項(xiàng)目實(shí)戰(zhàn)從入門到精通
- Visual Basic 6.0程序設(shè)計(jì)實(shí)驗(yàn)教程
- Java Web應(yīng)用開發(fā)項(xiàng)目教程
- 深入解析Java編譯器:源碼剖析與實(shí)例詳解
- Java程序設(shè)計(jì)教程
- Learning Unreal Engine Game Development