记一次踩雷经历:Vue引入vant /van-tabs组件后不显示/van-tabs和子路由的封装后Failed to resolve directive: keep-scroll-position

在Vue项目中,引入 vant/tabs 组件时遇到了显示问题和 keep-scroll-position 直接报错。错误源于按需引入 vant 的配置错误,尝试全局引入 vant 后问题依旧。排查发现,问题不在引入方式,而可能与自定义的 tabBar 组件有关。通过调整路由设置,将 tabBar 组件移至 app.vue 中,并监听 onChange 事件实现路由跳转,解决了问题。
摘要由CSDN通过智能技术生成

在这里插入图片描述
核心错误应该是[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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值