前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nuxt使用vant导航栏组件tabbar

Nuxt使用vant导航栏组件tabbar

作者头像
明知山
发布2021-01-21 06:32:45
9860
发布2021-01-21 06:32:45
举报
文章被收录于专栏:前端开发随笔前端开发随笔

按照我之前在vue/cli配置方法

发现watch事件刷新页面没有执行,而在vue/cli却执行

我也不想nuxt是什么原因、机制导致的

直接换种思路

组件components/tabbar.vue

代码语言:javascript
复制
<template>
  <van-tabbar v-model="isAct" inactive-color="#666666" active-color="#000000" fixed placeholder>
    <van-tabbar-item replace v-for="(item, index) in tabbarList" :key="index" :to="item.path">
      <span>{{ item.title }}</span>
      <img slot="icon" slot-scope="props" :src="props.active ? item.active : item.normal" />
    </van-tabbar-item>
  </van-tabbar>
</template>

<script>
  export default {
    name: "tabbar",
    data() {
      return {
        isAct: 0,
        tabbarList: [{
            path: "/",
            title: "首页",
            normal: "https://sucai.suoluomei.cn/sucai_zs/images/20190910093117-fx2.png",
            active: "https://sucai.suoluomei.cn/sucai_zs/images/20190910093117-fx.png",
          },
          {
            path: "/main",
            title: "我的",
            normal: "https://sucai.suoluomei.cn/sucai_zs/images/20190910093117-wd.png",
            active: "https://sucai.suoluomei.cn/sucai_zs/images/20190910093117-wd2.png",
          },
        ],
      };
    },
    props: {
      active: {
        type: [String, Number],
        default: 0,
      }
    },

    // 对active进行监听赋值
    watch: {
      active: {
        immediate: true,
        handler(value) {
          this.isAct = parseInt(value) //String类型无效,我也母鸡呀~
        }
      }
    }
  };
</script>

页面pages/index.vue

代码语言:javascript
复制
<template>
    <tabbar active=0></tabbar>
</template>

<script>
 import tabbar from '../components/tabbar.vue'
 export default {
    components: {
      tabbar
    },
 }
</script>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-01-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档