mixin.js - 方式一:导出对象
const mixin = {
mounted () {
console.log('fffffffffffff')
},
methods: {
}
}
export { mixin }
使用时,就应该使用对象的方式导入,即:{ mixin }
import { mixin } from './mixins/mixin'
export default {
mixins: [mixin]
}
mixin.js - 方式二:导出变量
const mixin = {
mounted () {
console.log('fffffffffffff')
},
methods: {
}
}
export default mixin
使用时,就应该使用变量的方式导入,即:mixin
import mixin from './mixins/mixin'
export default {
mixins: [mixin]
}
总结:导出导入方式要一致,否则就无法混入,会报错:Cannot read property 'components' of undefined