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

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.

主站蜘蛛池模板: 祁阳县| 藁城市| 昆山市| 盐源县| 文化| 潜山县| 定安县| 西畴县| 迁西县| 土默特左旗| 家居| 承德市| 聊城市| 焦作市| 临武县| 东安县| 陆河县| 信阳市| 砀山县| 农安县| 承德县| 县级市| 祁东县| 永和县| 玛多县| 洪江市| 大英县| 海宁市| 府谷县| 东兰县| 临海市| 固原市| 定远县| 麻栗坡县| 阳高县| 日照市| 韩城市| 黎城县| 嵊泗县| 益阳市| 永仁县|