收藏
回答

taro 自定义tabBar 开发工具显示正常,真机调试不显示?

import React, { Component } from 'react'
import { connect } from 'react-redux';
import { switchTab } from '@tarojs/taro'
import { CoverView, CoverImage, Text , View} from '@tarojs/components'
import './index.scss'

interface CustomTabBarState {
  dispatch,
  common,
}

const NORMAL_COLOR = '#999999'
const SELECTED_COLOR = '#FE7741'



@connect(({ common }) => ({
  common,
}))
export default class CustomTabBar extends Component<CustomTabBarState> {
  state = {
    current: 0,
  }
  

  changeTab = (item: any) => {
     const { dispatch } =this.props;
     switchTab({ url: item.pagePath })
    dispatch({
      type: 'common/updateState',
       payload: {
        selectedPath:item.pagePath
       },
    })
  }

  render() {
    const { common:{selectedPath, tabList }} = this.props; 
    return (
      <CoverView className='tab'>
        {tabList.map((item, index) => {
          return (
            <CoverView
              className='tab-item'
              onClick={this.changeTab.bind(this, item, index)}
              data-path={item.pagePath}
              key={item.text}
            >
              {/* 请使用 base64 格式,否则会存在性能问题 */}
                  <CoverImage
                    className='tab-item-img'
                    src={
                      selectedPath === item.pagePath ? item.selectedIconPath : item.iconPath
                    }
                  />
                  <View
                    className='tab-item-text'
                    style={{
                      color: selectedPath === item.pagePath ? SELECTED_COLOR : NORMAL_COLOR,
                    }}
                  >
                    {item.text}
                  </View>
                </CoverView>
              )
            })}
          </CoverView>
    )
  }
}


回答关注问题邀请回答
收藏

2 个回答

  • ° 度.
    ° 度.
    2021-08-12

    是没写这个属性么?

    2021-08-12
    有用
    回复 1
    • 小西瓜
      小西瓜
      2021-09-22
      我的看也没有 这个不是靠vscode编译出来的吗,不能单独在这里吗写吧
      2021-09-22
      回复
  • 😶
    😶
    2021-03-18

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2021-03-18
    有用
    回复
登录 后发表内容
问题标签