javascript - 如何把Vux的alert组件挂载到全局上
本文介绍了javascript - 如何把Vux的alert组件挂载到全局上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
项目中main.js中调用了,
import { AlertPlugin } from 'vux'
Vue.use(AlertPlugin);
Vue.prototype.$msgbox = (title,msg) => {
this.$vux.alert.show({
title: title,
content: msg
});
}
这样子调用会报错Error in mounted hook: "TypeError: Cannot read property 'alert' of undefined"。
求问要如何才可以把alert组件像这样子挂载到全局函数上去?
这个问题已被关闭,原因:问题已解决 - 问题已解决,且对他人无借鉴意义
解决方案
Vue.prototype.$msgbox = function(title, msg) {
this.$vux.alert.show({
title: title,
content: msg
});
}
这里不要用箭头函数
这篇关于javascript - 如何把Vux的alert组件挂载到全局上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文