錯誤一:
[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中添加的,所以得引入相應的插件。