[置顶] 解决vux 引入组件时Error in render function: "TypeError: _vm.$t is not a function"问题
2017-08-23 14:38
1896 查看
vux是基于vue.js的一个组件集合,有时候导入组件是遇到各种报错。
例如,我们引入常用的vux-Datetime组件:
正确引入后控制台发出各种报错:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202010/18/5785036923ef62812224764874f36417)
这种报错在官网的解释是:
下面的$t是i18n使用的翻译函数,一般情况下可以直接使用字符串。
也没有给出更快的解决方案:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202010/18/e45405752d38d32601280e028c2952f3)
所以我在这里给出这个问题的解决方法,其实特别简单,只要在main.js文件里引入vuex 和 vuexI18n 插件并引用即可。关键看代码:
为什么必须要设置 add 和 set方法,这我就不太清楚了,我只是找到了解决方法。
这是这插件在项目里的效果:
例如,我们引入常用的vux-Datetime组件:
<script> import pcHead from '@/components/Public/Pc-Head' import {Datetime } from 'vux' export default { name: "", data: function data() { return { value: '2015-11-12' } }, components: { pcHead, Datetime }, mounted: function mounted() { this.$nextTick(() => { }) } } </script>
<datetime v-model="value"></datetime>
正确引入后控制台发出各种报错:
这种报错在官网的解释是:
下面的$t是i18n使用的翻译函数,一般情况下可以直接使用字符串。
也没有给出更快的解决方案:
所以我在这里给出这个问题的解决方法,其实特别简单,只要在main.js文件里引入vuex 和 vuexI18n 插件并引用即可。关键看代码:
import Vuex from 'vuex'; import vuexI18n from 'vuex-i18n'; Vue.use(VueResource); 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" }; // translations can be kept in separate files for each language // i.e. resources/i18n/de.json. // add translations directly to the application Vue.i18n.add('en', translationsEn); // set the start locale to use Vue.i18n.set('en');
为什么必须要设置 add 和 set方法,这我就不太清楚了,我只是找到了解决方法。
这是这插件在项目里的效果:
相关文章推荐
- chrome浏览器Uncaught TypeError: object is not a function问题解决
- vuejs路由使用的问题Error in render function: "TypeError: Cannot read property 'matched' of undefined"
- [置顶] Android开发之解决Error:(16) Error: "ssdk_baidutieba_client_inavailable" is not translated in "en" (Englis
- chrome浏览器Uncaught TypeError: object is not a function问题解决
- chrome浏览器Uncaught TypeError: object is not a function问题解决
- TypeError: newRawData.forEach is not a function问题解决
- [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined、vuejs路由使用的问题Error in render function
- jsp引入bootstrap、bootstrap-Validator后出现xxx is not a function的问题及解决办法!
- chrome浏览器Uncaught TypeError: object is not a function问题
- Uncaught TypeError: $(...).Validform is not a function 如何解决,以及其他方式替换jquery功能
- chrome浏览器Uncaught TypeError: object is not a function问题
- 解决"eker is not in the sudoers file"问题
- 解决Uncaught TypeError: object is not a function
- jQuery Validation插件onfocosout/onkeyup出错的解决方法[Uncaught TypeError: undefined is not a function中文资料不好找]
- iOS iOS8中 问题"registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later" 解决方式
- Uncaught (in promise) TypeError: __webpack_require__.i(...) is not a function
- AS打包apk及常见错误解决办法Error:(4) Error: "ssdk_instapager_login_html" is not translated in "en" (English)
- JS报错 Uncaught TypeError: undefined is not a function,解决
- 解决"Bower : ENOGIT git is not installed or not in the PATH"问题
- TypeError: validator.settings[("on" + event.type)].call is not a function