在VUE项目中,我们想把一些主要的代码抽到一个模块中
export default {
/**
* 获取本地的群列表数据
* @param {*} params
*/
getGroupList () {
// 这里的this指向的是当前的对象,我们一般想要的是VUE实例的this
}
}
有两种方法,
main.js
let vue = new Vue({
components: { App },
router,
store,
i18n,
template: '<App/>'
}).$mount('#app')
export default vue
当前摸块引用
/**
* 群聊相关的增,删,改,查
*/
import _this from '../../main.js'
export default {
/**
* 获取本地的群列表数据
* @param {*} params
*/
getGroupList () {
const getList = _this.$db.models.User
getList.getUser({
userId: _this.$store.getters.userId
}).then(res => {
console.log(res)
})
}
}
解决问题。
原文:https://www.cnblogs.com/ybixian/p/10706282.html