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

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.

主站蜘蛛池模板: 平安县| 泰和县| 五华县| 安乡县| 合阳县| 张家口市| 黄石市| 广昌县| 大洼县| 灌南县| 尚义县| 宣威市| 岳西县| 乌鲁木齐市| 屯门区| 鹿邑县| 东乡族自治县| 石狮市| 长白| 沂南县| 凤城市| 察隅县| 锦州市| 东明县| 南投市| 北安市| 麻城市| 盐池县| 常山县| 临武县| 南投县| 卢龙县| 湘西| 东丽区| 土默特右旗| 台中县| 易门县| 咸丰县| 莲花县| 大安市| 乌兰察布市|