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

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.

主站蜘蛛池模板: 台州市| 彩票| 科尔| 遂宁市| 榆林市| 保山市| 淅川县| 弋阳县| 淮北市| 苏尼特左旗| 平邑县| 黑山县| 青浦区| 河北区| 泸定县| 衡东县| 交城县| 宁河县| 竹山县| 图片| 莱州市| 台东县| 洛扎县| 卫辉市| 洛扎县| 伊宁县| 巨野县| 融水| 七台河市| 上思县| 彰化县| 青浦区| 化德县| 涡阳县| 郸城县| 治县。| 兴仁县| 时尚| 沛县| 商水县| 贺兰县|