在全局中:
//main.js中
Vue.mixin({
data() {
return {
}
},
computed: {
app: () => _app,
local: () => _local,
lang: () => _lang,
images: () => _images,
},
methods: {
replaceLang,
replaceLangBR,
toast,
profile,
track,
track2,
},
})
//使用的时候,直接用,例如toast,this.toast()
在config文件中,创建一个mixin.js
export const mixin = {
data() {
return {
}
},
mounted() {
},
methods: {
// 全局刷新
refresh() {
this.$store.dispatch('getInitInfo');
this.$store.dispatch('rank');
this.$store.dispatch('tips');
},
}
}
使用:
去使用到的地方引入
import { mixin } from "../config/mixin"
export default {
mixins: [mixin], //重点这个
}