国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue父子組件的嵌套的示例代碼

2019-11-19 15:30:37
字體:
來源:轉載
供稿:網友

本文介紹了vue父子組件的嵌套的示例代碼,分享給大家,具體如下:

組件的注冊:

先創建一個構造器

var myComponent = Vue.extend({  template: '...'})

用Vue.component注冊,將構造器用作組件(例為全局組件)

Vue.component('my-component' , myComponent)

注冊局部組件:

var Child = Vue.extend({ /* ... */ })var Parent = Vue.extend({ template: '...', components: {  // <my-component> 只能用在父組件模板內  'my-component': Child }})

注冊語法糖,簡化過程

// 在一個步驟中擴展與注冊Vue.component('my-component', { template: '<div>A custom component!</div>'})// 局部注冊也可以這么做var Parent = Vue.extend({ components: {  'my-component': {   template: '<div>A custom component!</div>'  } }})

父子組件嵌套的例子:

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>index</title></head><body><div id="app">  <parent></parent></div><script src="vue.js"></script><script>  var childComponent = Vue.extend({    template: '<p>this is child template</p>'  });  Vue.component("parent",{    template: '<p>this is parent template</p><child></child><child></child>',    components: {      'child': childComponent,    }  });  var app = new Vue({    el: '#app'  });</script></body></html>

其與以下寫法等價:

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>index</title></head><body><template id="child">  <p>this is child template</p></template><template id="parent">  <p>this is parent template</p>  <child></child>  <child></child></template><div id="app">  <parent></parent></div><script src="vue.js"></script><script>  var childComponent = Vue.extend({    template: '#child'  });  Vue.component("parent",{    template: '#parent',    components: {      'child': childComponent,    }  });  var app = new Vue({    el: '#app'  });</script></body></html>

頁面顯示:


以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临洮县| 鄂托克旗| 普兰店市| 鄢陵县| 九江市| 肥西县| 吕梁市| 鄯善县| 元氏县| 广饶县| 红原县| 大名县| 都兰县| 锡林浩特市| 象山县| 原阳县| 龙江县| 蓝田县| 荣昌县| 绥宁县| 景德镇市| 滨海县| 宁远县| 恩施市| 泗阳县| 靖安县| 额敏县| 新郑市| 宜君县| 曲松县| 资阳市| 通辽市| 华坪县| 西吉县| 仙桃市| 达孜县| 石柱| 从化市| 开鲁县| 南澳县| 四川省|