官網(wǎng):混合 (mixins) 是一種分發(fā) Vue 組件中可復(fù)用功能的非常靈活的方式?;旌蠈?duì)象可以包含任意組件選項(xiàng)。以組件使用混合對(duì)象時(shí),所有混合對(duì)象的選項(xiàng)將被混入該組件本身的選項(xiàng)。
個(gè)人:混入就是用來(lái)對(duì)vue組件中的公共部分,包括數(shù)據(jù)對(duì)象、鉤子函數(shù)、方法等所有選項(xiàng),進(jìn)行提取封裝,以達(dá)到代碼的復(fù)用,混合用處挺大的,然我們來(lái)看看實(shí)際用法。
基礎(chǔ)用法
// 這是在main.js根文件中使用,在組中使用也是一樣 import Vue from 'vue'; var mixin = { data() { return { name: 'www.vipbic.com', author: '羊先生' } }, created: function() { console.log('Website:' + this.name) }, methods: { foo: function() { console.log('作者:' + this.author) }, conflicting: function() { console.log('from mixin') } } } new Vue({ mixins: [mixin], render: h => h(App), created() { let option = this.$options.doNotInit console.log('option:', ); this.foo() } }).$mount('#app') // 在組建中使用 <template><div></div></template> <script> var mixin = { data() { return { name: 'www.vipbic.com', author: '羊先生' } }, created: function() { console.log('Website:' + this.name) }, methods: { foo: function() { console.log('作者:' + this.author) } } } export default { mixins: [mixin], created(){ this.foo() } } </script>
文章名稱(chēng):Vue如何使用混合Mixins和插件開(kāi)發(fā)詳解-創(chuàng)新互聯(lián)
文章鏈接:http://jinyejixie.com/article48/dcjghp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、關(guān)鍵詞優(yōu)化、網(wǎng)站維護(hù)、ChatGPT、小程序開(kāi)發(fā)、定制開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容