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

首頁 > 開發(fā) > JS > 正文

淺析vue component 組件使用

2024-05-06 16:35:36
字體:
供稿:網(wǎng)友

component 使用

component的注冊(cè)

1.全局注冊(cè)

使用用Vue.component('componentName',{template:'<div class="tem1">hello world</div>'})在初始化實(shí)例之前。

componentName自定義名稱

在實(shí)例聲明的作用域下中使用<componentName></componentName> 成功渲染效果就是 '<div class="tem1">hello world</div>

Vue.component('my-component',{       template:'<div class="tem1">hello world</div>'     }  

組件中的數(shù)據(jù)使用 

component不能使用實(shí)例的data ,但是可以在component 使用data 聲明變量,data的使用只能使用函數(shù)形式

Vue.component('my-component',{       template:'<div class="tem1">hello world {{comdata}}</div>',       data:function(){return {comdata:'hehe'}}     });

2.局部主持

在實(shí)例化的new Vue 中設(shè)置components

var app=new Vue({       el:'#app',       components:{'example':{template:'<div>children template</div>'}}     }) 

組件中的數(shù)據(jù)使用

var app=new Vue({       el:'#app',       data:{num:220},       components:{         'example':{           template:'<div>children template{{mydata}}</div>',           data:function(){return {mydata:' mydata=data'};}         }        }     })

注意:組件不能使用實(shí)例的data:{num:220}的參數(shù)會(huì)報(bào)錯(cuò)

組件中同樣支持methods、computed等其他屬性 不會(huì)沖突保持相對(duì)的獨(dú)立

這時(shí)候就必須考慮不同組件的數(shù)據(jù)通信問題

vue js總結(jié)來說通過props down events up 來傳輸數(shù)據(jù)

給父級(jí)調(diào)用數(shù)據(jù)使用props聲明,給子集調(diào)用使用events來聲明

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到JavaScript/Ajax教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 香港 | 界首市| 霍城县| 屏东市| 乌拉特前旗| 米脂县| 卢氏县| 连南| 财经| 凌云县| 瑞丽市| 山阴县| 吴桥县| 茌平县| 海阳市| 延吉市| 望城县| 沂源县| 垣曲县| 沾益县| 天水市| 礼泉县| 连州市| 呼伦贝尔市| 湟源县| 扎兰屯市| 西城区| 宿迁市| 宜宾市| 会理县| 南雄市| 夏邑县| 宁阳县| 岑溪市| 永安市| 独山县| 台江县| 平昌县| 崇左市| 葵青区| 石楼县|