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

首頁 > 開發 > JS > 正文

詳解vue父子模版嵌套案例

2024-05-06 16:35:35
字體:
來源:轉載
供稿:網友

這里是父子模版的調用

這里是針對于vue1.0,如果要學2.0,建議大家去看官方文檔

vue2.0 :http://vuefe.cn/guide/

vue-router2.0: https://router.vuejs.org/zh-cn/essentials/getting-started.html

第一種,子組件模版直接寫在js里

//定義模版掛載點my-component<div id="exampleBox1">   <com-ponent></com-ponent></div><script src="../vue/node_modules/vue/dist/vue.js"></script><script>   var Component = Vue.extend({// 定義  template: '<div>A custom component!</div>',  data: function () {    return {      name: 'yuxie'     }  }});Vue.component('com-ponent', Component);// 注冊 //注意,extend(json) 和 vue.component('com-ponent', json)//這兩個JSON是相等的。//所以下面第二種會將extend()函數省略掉,直接在component中定義,系統會自動調用extend函數。  var conp = new Vue({// 創建根實例    el: '#exampleBox1'    });</script>

第二種,使用HTML模版

<!-- 父組件模板 --><div id="exampleBox2" style="border:1px solid #ccc;width:500px;">  <div>{{parent.name}}</div>  <!--模版掛載標識-->  <children></children></div><!-- 子組件模板 --><template id="child-template">   <p style="background:#eee;">{{text}}</p></template><script> Vue.component('children', {//child是模版掛載的標簽名       template: '#child-template',//id對應子組件的ID       data: function () {           return {               text: '這里是子組件的內容'           }       }  });  var parent = new Vue({// 初始化父組件        el: '#exampleBox2',        data: {            parent: {                 name:'這里是父組件的內容'            }           }   })</script>

第三種、來一個復雜的

<div id="example">  <!--  所有的模板掛件,都必須在根實例ID內部,否則找不到掛件  -->  <my-component></my-component>  <!-- 模版可以重用多次 ···· 只不過一樣的東西沒有這個必要 -->  <child></child>復用一次  <child></child>復用二次  <child></child> ···  <child></child> ···</div><!--比如放在這里是找不到的--><child></child><script src="../vue/node_modules/vue/dist/vue.js"></script><script>//定義子組件,子組件必須在父組件之前定義。  var Child = Vue.extend({template: '<div>A child component!</div>'}); //定義父組件var Parent = Vue.extend({  template: '<div style="border: 1px solid #ccc;width:200px;">Parent<child-component></child-component>父模版內部</div>',      components: {       // 調用子組件        'child-component': Child      }   });   // 注冊父組件   Vue.component('my-component', Parent);  //復用子組件。  Vue.component('child', Child);   // 創建根實例,所有組件都需要在根實例之前創建。  new Vue({     el: '#example'   })</script>

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


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泸西县| 孟津县| 车险| 景谷| 商南县| 黑龙江省| 阿瓦提县| 淅川县| 玛曲县| 体育| 胶州市| 唐河县| 巴林右旗| 五华县| 兖州市| 金乡县| 环江| 呼伦贝尔市| 布尔津县| 五常市| 宜州市| 奇台县| 唐河县| 韶山市| 昔阳县| 和林格尔县| 泽库县| 武安市| 屯门区| 蕲春县| 余干县| 介休市| 岳阳县| 治多县| 桂平市| 苗栗市| 通渭县| 鲜城| 嘉峪关市| 乌鲁木齐市| 鲜城|