官網(wǎng):混合 (mixins) 是一種分發(fā) Vue 組件中可復(fù)用功能的非常靈活的方式?;旌蠈ο罂梢园我饨M件選項。以組件使用混合對象時,所有混合對象的選項將被混入該組件本身的選項。
個人:混入就是用來對vue組件中的公共部分,包括數(shù)據(jù)對象、鉤子函數(shù)、方法等所有選項,進行提取封裝,以達到代碼的復(fù)用,混合用處挺大的,然我們來看看實際用法。
基礎(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>
文章名稱:Vue如何使用混合Mixins和插件開發(fā)詳解-創(chuàng)新互聯(lián)
文章鏈接:http://chinadenli.net/article48/dcjghp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、關(guān)鍵詞優(yōu)化、網(wǎng)站維護、ChatGPT、小程序開發(fā)、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)