国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Vue 組件注冊(cè)全解析

瀏覽:116日期:2022-10-18 18:15:55
全局組件注冊(cè)語(yǔ)法

components中的兩個(gè)參數(shù)組件名稱和組件內(nèi)容

Vue.component(組件名稱, { data: 組件數(shù)據(jù), template:組件模板內(nèi)容 })全局組件注冊(cè)應(yīng)用

組件創(chuàng)建:

Vue.component(’button-counter’, { data: function(){ return { count: 0 } }, template: ’<button @click='handle'>點(diǎn)擊了{(lán){count}}次</button>’, methods: { handle: function(){ this.count ++; } } }) var vm = new Vue({ el: ’#app’, data: { } });

如何在頁(yè)面中運(yùn)用,直接在頁(yè)面中應(yīng)用組件名稱

<div id='app'> <button-counter></button-counter></div>

這個(gè)組件是可以重用的,直接在頁(yè)面中多次使用,切數(shù)據(jù)相互獨(dú)立,互不干擾

組件注冊(cè)注意事項(xiàng)

1.data必須是一個(gè)函數(shù)

分析函數(shù)與普通對(duì)象的對(duì)比

2.組件模板內(nèi)容必須是單個(gè)根元素

分析演示實(shí)際的效果

3.組件模板內(nèi)容可以是模板字符串

模板字符串需要瀏覽器提供支持(ES6語(yǔ)法)

4.組件命名方式

短橫線方式

Vue.component(’my-component’,{/*...*/})

駝峰方式

Vue.component(’MyComponent’,{/*...*/})

如果使用駝峰式命名組件,那么在使用組件的時(shí)候,只能在字符串模板中用駝峰的方式使用組件,但是在普通的標(biāo)簽?zāi)0逯校仨毷褂枚虣M線的方式使用組件

局部組件

局部組件只能在注冊(cè)它的父組件中使用

局部組件注冊(cè)語(yǔ)法

var ComponentA = {/*...*/}var ComponentB = {/*...*/}var ComponentC = {/*...*/}new Vue({ el : ’#app’, components: {’component-a’ : ComponentA,’component-b’ : ComponentB,’component-c’ : ComponentC}})

組件的創(chuàng)建

Vue.component(’test-com’,{ template: ’<div>Test<hello-world></hello-world></div>’ }); var HelloWorld = { data: function(){ return { msg: ’HelloWorld’ } }, template: ’<div>{{msg}}</div>’ }; var HelloTom = { data: function(){ return { msg: ’HelloTom’ } }, template: ’<div>{{msg}}</div>’ }; var HelloJerry = { data: function(){ return { msg: ’HelloJerry’ } }, template: ’<div>{{msg}}</div>’ }; var vm = new Vue({ el: ’#app’, data: { }, components: { ’hello-world’: HelloWorld, ’hello-tom’: HelloTom, ’hello-jerry’: HelloJerry } });

頁(yè)面中的應(yīng)用

<div id='app'> <hello-world></hello-world> <hello-tom></hello-tom> <hello-jerry></hello-jerry> <test-com></test-com> </div>

以上就是Vue 組件注冊(cè)全解析的詳細(xì)內(nèi)容,更多關(guān)于Vue 組件注冊(cè)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 肇东市| 清苑县| 石屏县| 湘潭市| 定结县| 宁乡县| 鄯善县| 永川市| 新泰市| 陆川县| 醴陵市| 驻马店市| 夏邑县| 翁牛特旗| 尉犁县| 昌宁县| 济宁市| 无为县| 犍为县| 南通市| 绵阳市| 和林格尔县| 茌平县| 正安县| 旅游| 鄂伦春自治旗| 灵石县| 东乡县| 莱阳市| 高唐县| 交城县| 朝阳区| 苏尼特左旗| 宿松县| 华宁县| 长岭县| 汶上县| 湘乡市| 高尔夫| 开鲁县| 化德县|