定义一个mixin.js,我的文件路径为 : common/mixin.js
let MIXIN = {
data() {
return {
name: 'mixin'
}
},
created() {
console.log('mixin...', this.name);
},
mounted() {},
methods: {}
};
export default MIXIN;
引用mixin ,mixin分全局引用和局部引用。
//全局引用
import mixin from './common/mixin.js'
Vue.mixin(mixin)
//在vue文件中引用
import mixin from '../common/mixin.js'; // 引入mixin文件
export default {
mixins: [mixin]
}
网友评论