官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 泸水县| 五寨县| 日照市| 荆州市| 宁波市| 涞源县| 丰县| 蓬莱市| 贺州市| 尼玛县| 客服| 常熟市| 洮南市| 亳州市| 巨鹿县| 博乐市| 班戈县| 阳谷县| 扶余县| 莱芜市| 永德县| 东明县| 沿河| 富裕县| 麦盖提县| 高台县| 延边| 澄江县| 西安市| 苍梧县| 子长县| 陇西县| 旬邑县| 宜宾县| 宁都县| 闻喜县| 宁河县| 镇巴县| 天台县| 仪陇县| 台前县|