使用vux组件库常见报错($t)处理

错误一:

[Vue warn]: Property or method "$t" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

解决方案:

如果没有安装vuex和vuex-i18n需要先安装,然后在main.js中引入以下代码。在new Vue的时候,把store写上

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app-box')

 

import Vuex from 'vuex';
import vuexI18n from 'vuex-i18n';
Vue.use(Vuex);
const store = new Vuex.Store({
  modules: {
    i18n: vuexI18n.store
  }
});
Vue.use(vuexI18n.plugin, store);
const translationsEn = {
  "content": "This is some {type} content"
};

Vue.i18n.add('en', translationsEn);
Vue.i18n.set('en'); 

  或者直接把$t删除,直接用相应的汉语或者英语。

  $t是一个翻译函数,如果你的项目不需要国际化,切换语言,那么你就可以把$t删除。

 

 错误二:

 Uncaught TypeError: Cannot read property 'alert' of undefined at eval

解决方案:

import { AlertPlugin, DatetimePlugin, ConfirmPlugin, LoadingPlugin, ToastPlugin } from 'vux'
Vue.use(AlertPlugin)
Vue.use(DatetimePlugin)
Vue.use(ConfirmPlugin)
Vue.use(LoadingPlugin)
Vue.use(ToastPlugin)

  在main.js中加入以上代码,没有用到的插件可以不引入。以上几个是我总结出来的容易报错的几个插件。错误原因是你的代码中使用了 this.$vux.alert等类似代码,而$vux是在插件中向vue中添加的,所以得引入相应的插件。

转载于:https://www.cnblogs.com/zhaodesheng/p/9056738.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值