收藏
回答

小程序使用自定义tabBar图片为什么无法显示?

开发者工具中显示正常,而真机就不显示图片,图片使用英语命名,均小于5kb,且文字显示正常。

代码如下:
js:
var app = getApp();
Component({
    data: {
        selected0,
        color"#9E70C",
        roleId'',
        selectedColor"#212121",
        tabList: [{


            list1: [{
                "pagePath""/pages/lesson/lesson",
                "text""课程",
                "iconPath""/images/lesson.svg",
                "selectedIconPath""/images/lesson.svg"
                },
                {
                "pagePath""/pages/user/user",
                "text""用户",
                "iconPath""/images/user.svg",
                "selectedIconPath""/images/user.svg"
                }
            ],




            list2: [
                {
                    "pagePath""/pages/lesson/lesson",
                    "text""课程",
                    "iconPath""/images/lesson.svg",
                    "selectedIconPath""/images/lesson.svg"
                },
                {
                    "pagePath""/pages/manageall/manageall",
                    "text""管理",
                    "iconPath""/images/manage.svg",
                    "selectedIconPath""/images/manage.svg"
                },
                {
                    "pagePath""/pages/user/user",
                    "text""用户",
                    "iconPath""/images/user.svg",
                    "selectedIconPath""/images/user.svg"
                },
            ],
        }],
        list: []
    },
    pageLifetimes:{
        show:function(){
            console.log("show")
            const roleId = app.globalData.type
            if (roleId == 0) {
                console.log("show") 
                this.setData({
                    listthis.data.tabList[0].list1
                })
            } else if (roleId == 1) {
                this.setData({
                    listthis.data.tabList[0].list2
                })
            }else{
                this.setData({
                    list:this.data.tabBarList[0].list1
                })
            }
        },
        hide:function(){
            console.log("hide")
            const roleId = app.globalData.type
            if (roleId == 0) {
                console.log("show") 
                this.setData({
                    listthis.data.tabList[0].list1
                })
            } else if (roleId == 1) {
                this.setData({
                    listthis.data.tabList[0].list2
                })
            }else{
                this.setData({
                    list:this.data.tabList[0].list1
                })
            }
        }
    },
    attached() {
        console.log("attached")
        var roleId = app.globalData.type
        console.log(app.globalData.type)
        if (roleId == 0) { 
            this.setData({
                listthis.data.tabList[0].list1
            })
        } else if (roleId == 1) {
            this.setData({
                listthis.data.tabList[0].list2
            })
        }else{
            this.setData({
                listthis.data.tabList[0].list1
            })
        }
    },
    detached:function(){
        console.log("detached")
        const roleId = app.globalData.type
            if (roleId == 0) {
                console.log("show") 
                this.setData({
                    listthis.data.tabList[0].list1
                })
            } else if (roleId == 1) {
                this.setData({
                    listthis.data.tabList[0].list2
                })
            }else{
                this.setData({
                    listthis.data.tabList[0].list1
                })
            }
    },
    methods: {
        switchTab(e) {
            const data = e.currentTarget.dataset
            const url = data.path
            wx.switchTab({ url })
            this.setData({
                selected: data.index
            })
        }
    },




})
wxml:
<cover-view class="tab-bar">
    <cover-view class="tab-bar-border"></cover-view>
    <cover-view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab">
      <cover-image src="{{item.iconPath}}"></cover-image>
      <cover-view :style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</cover-view>
    </cover-view>
  </cover-view>
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容