(1)、准备一个对象(类似于组件的写法)
export default {
data(){
return {
age:18
}
},
methods:{
handleClick(){
console.log('mixins中的点击事件',this)
}
},
mounted(){
console.log('混入的生命周期',this)
}
}
(2)、使用mixins引入对应的组件
<script>
import mycommn from './common.js'
export default {
name: 'HelloWorld',
mixins: [mycommn],
data(){
return {
userInfo:{
lastName:'wenqiang',
firstName:'guo'
},
age:20
}
},
mounted(){
console.log('组件内生命周期')
},
props: {
msg: String
}
}
</script>