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

首頁 > 語言 > JavaScript > 正文

深入淺析Vue全局組件與局部組件的區(qū)別

2024-05-06 15:33:23
字體:
供稿:網(wǎng)友

1、組件聲明

<!-- 全局組件模板father模板 --> <template id="father">   <div>      <h3>這是{{name}}</h1>      <div>        <p>這是{{data}}</p>      </div>   </div> </template> var FATHER = {   template: "#father",   data: function() {      return {        name: "一個全局組件-模板-",        data: "數(shù)據(jù):18892087118"      }    }  }; 

2、組件注冊

Vue.component('father', FATHER); 

3、組件掛載

<h5>全局組件1</h5> <father></father> 

4、組件實例

<!DOCTYPE html> <html> <head>   <title>vue2.0 --- 局部組件與全局組件</title> </head> <body>   <h3>vue2.0局部組件與全局組件</h3>   <div id='app'>     <h5>局部組件</h5>     <fatherlocal></fatherlocal>     <hr>     <h5>全局組件1</h5>     <father></father>     <hr>     <h5>全局組件2</h5>     <child :fromfather='giveData'></child>   </div>   <!-- 局部組件模板fatherlocal -->   <template id="father-local">     <div>       <h3>這是{{name}}</h1>       <div>         <p>這是{{data}}</p>       </div>     </div>   </template>   <!-- 全局組件模板father -->   <template id="father">     <div>       <h3>這是{{name}}</h1>       <div>         <p>這是{{data}}</p>       </div>     </div>   </template>   <template id="child">     <div>       <h3>這是{{name}}</h3>       <div>         <p>{{cmsgtwo}}</p>         <p>{{cmsg}}</p>         <p>{{fromfather}}</p>         <p>{{fromfather.fmsg}}</p>         <p><input type="button" value="按鈕" @click=" "></p>       </div>     </div>   </template>   <script src="vue_2.2.2_vue.min.js"></script>   <script type="text/javascript">     // 定義組件     var FATHER = {       template: "#father",       data: function() {         return {           name: "一個全局組件-模板-",           data: "數(shù)據(jù):18892087118"         }       }     };     var CHILD = {       template: "#child",       data: function() {         return {           name: "子組件",           cmsg: "子組件里的第一個數(shù)據(jù)",           cmsgtwo: "子組件里的第二個數(shù)據(jù)"         }       },       methods: {         change: function() {           this.fromfather.fmsg = "子組件數(shù)據(jù)被更改了"         }       },       mounted: function() {         this.cmsg = this.fromfather;       },       props: ["fromfather"],     };     // 注冊組件     Vue.component('father', FATHER);     Vue.component("child", CHILD);     var vm = new Vue({       data: {         fmsg: "data里的數(shù)據(jù)",         giveData: {           fmsg: "這是父組件里的數(shù)據(jù)"         }       },       methods: {},       // 局部組件fatherlocal       components: {         'fatherlocal': {           template: '#father-local',           data: function() {             return {               name: "局部-父組件",               data: "局部-父組件里的數(shù)據(jù)"             }           }         }       }     }).$mount('#app');   </script> </body> </html>             
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 苗栗县| 深圳市| 陆丰市| 靖宇县| 抚州市| 东兰县| 平陆县| 温泉县| 印江| 深州市| 中宁县| 玛曲县| 上虞市| 崇州市| 怀柔区| 普兰店市| 泉州市| 两当县| 贵阳市| 五常市| 安国市| 宣汉县| 兴山县| 塘沽区| 金湖县| 鹿邑县| 丁青县| 奉新县| 安丘市| 华蓥市| 上栗县| 榆林市| 阳城县| 岫岩| 教育| 寿光市| 荆门市| 永安市| 五指山市| 屯留县| 卓尼县|