一、文章由來
在開發過程中發現在鉤子函數位置直接使用dicts就能直接綁定數據了,由此溯源發現了自己的盲區
二、局部使用
// myMixin.js文件
var myMixin = {created: function () {this.hello()},methods: {hello: function () {console.log('hello from mixin!')}}
}
使用
mixins: [mixin],
三、全局使用
Vue.mixin({created: function () {var dicts= this.$options.dicts // 通過this.$options可以過去到所有鉤子函數和自定義的同級方法if (dicts) {console.log(dicts) //打印結果: ["insurance_type","insurance_mode","livestock_type"]}}
})
使用
// dicts是和鉤子函數同級的
dicts: ["insurance_type","insurance_mode","livestock_type"],