custom-tabbar.vue 1.7 KB
<template>
  <view>
    <u-tabbar
      :value="vuex_tabbar_index"
      :fixed="true"
      :safeAreaInsetBottom="true"
      :placeholder="true"
      :activeColor="vuex_active_color"
    >
      <u-tabbar-item
        v-for="(tabbarItem, index) in vuex_tabbar"
        :key="index"
        :text="tabbarItem.text"
        @click="switchTo()"
      >
        <image
          class="image_class"
          slot="active-icon"
          :src="tabbarItem.selectedIconPath"
        ></image>
        <image
          class="image_class"
          slot="inactive-icon"
          :src="tabbarItem.iconPath"
        ></image>
      </u-tabbar-item>
    </u-tabbar>
  </view>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "custom-tabbar",
  data() {
    return {
      tabbar: [], // tabbar信息
    };
  },
  // 自定义组件中属性
  props: ["activeColor"],
  created() {
    // 模拟调用服务端接口,显示首页和我的页面
    // if (this.tabbarState == 1) {
    //   const storeTabbar = this.vuex_tabbar;
    //   this.tabbar = this.tabbar.concat(storeTabbar[0]).concat(storeTabbar[2]);
    // }
    // // 模拟调用服务端接口,显示首页、消息和我的页面
    // if (this.tabbarState == 2) {
    //   this.tabbar = this.vuex_tabbar;
    // }
    // this.tabbar = this.vuex_tabbar;
  },
  methods: {
    // 页面跳转
    switchTo(event) {
      const _this = this
      wx.switchTab({
        url: this.vuex_tabbar[event].pagePath,
        success: () => {
          this.$u.vuex('vuex_tabbar_index', event);
        },
      });
    },
  },
};
</script>

<style lang="scss">
.image_class {
  width: 50rpx;
  height: 50rpx;
}
</style>