核心错误应该是[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
和下面的提示Error in render: "TypeError: _vm.$t is not a function"
以及最后的TypeError: "_vm.$t is not a function"
问题出现在我是按需引入的插件,在main.js中引入的时候出错了,可以看到tabbar下面有个小波浪号,首字母要大写
如果此时还是出错,则删掉npm uninstall i babel-plugin-import -D
按需引入的,以及相关的js配置文件中一起删掉,选择全部一起引入,否则会找不到Vant。
但是当vant可以全局引入的时候会报同样的错误。所以应该不是引入方式的问题,网上普遍说是引入vux插件的问题,但是我又没有引入这个插件。并且我在引入button的时候是没有问题的,因此问题应该出现在我引入的tabBar。
<!--下方的TabBar-->
<van-tabbar v-model="tabBarSelect">
<van-tabbar-item v-for="(item, i) in tabItemList" :key="i" :to="item.to" replace>
<div class="tab-txt">{
{
$t(item.name)}}</div>
<img :src="getTabIconSrc(item, props.active)" slot="icon" slot-scope="props" class="icon-img"/>
</van-tabbar-item>
</van-tabbar>
然后这里的tabitemlist是这样的,我确保了图片和路径的正确,img主要是想要一个点击之后的高亮:
tabItemList: [
{
active: 'main_tab_3.png',
normal: 'main_tab_2.png',
name: 'tab_home',
to: "home"
},
{
active: 'main_tab_5.png',
normal: 'main_tab_4.png',
name: 'tab_products',
to: "products"
},
{
active: 'main_tab_7.png',
normal: 'main_tab_6.png',
name: 'tab_discovery',
to: "discover"
},
{
active: 'main_tab_1.png',
normal: 'main_tab_8.png',
name: 'tab_mine',
to: "mine"
},
],
首先我测试了一下别的方式引入tabbar是不会出错的,进一步说明不是引入的问题。
<van-tabbar v-model="tabBarSelect" >
<van-tabbar-item icon