使用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')
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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
解决方案:
1 2 3 4 5 6 | 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中添加的,所以得引入相应的插件。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现