导航

    Taro 社区

    Taro

    • 注册
    • 登录
    • 搜索
    • 版块
    • 最新
    • 话题
    • 热门
    • 群组
    1. 主页
    2. lhuanyu123
    3. 帖子
    L
    • 资料
    • 关注
    • 粉丝
    • 主题
    • 帖子
    • 最佳
    • 群组

    lhuanyu123 发布的帖子

    • typescript在taro中有点问题?

      根据taro cli创建typescript项目,修改src\pages\index\index.tsx文件:

      import Taro, { Component, Config } from '@tarojs/taro'
      import { View, Text } from '@tarojs/components'
      import './index.scss'
      
      type State = {
        // list: any[]
      }
      
      interface Props{}
      
      export default class Index extends Component<Props, State> {
      
        /**
         * 指定config的类型声明为: Taro.Config
         *
         * 由于 typescript 对于 object 类型推导只能推出 Key 的基本类型
         * 对于像 navigationBarTextStyle: 'black' 这样的推导出的类型是 string
         * 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型
         */
        config: Config = {
          navigationBarTitleText: '首页'
        }
      
        state = {
          list: [
            {selected: true,text: 'one'},
            {selected: true,text: 'two'},
            {selected: true,text: 'three'},
            {selected: false,text: 'three'}
          ]
        }
      
        componentWillMount () { }
      
        componentDidMount () { }
      
        componentWillUnmount () { }
      
        componentDidShow () { }
      
        componentDidHide () { }
      
        render () {
          const list = this.state.list.map(l => {
            if (l.selected) {
              return <li>{l.text}</li>
            }
          }).filter(Boolean)
          return (
            <View className='index'>
              <View className='test'>测试是否自适应web桌面网页</View>
              {list}
              <Text>Hello world!</Text>
            </View>
          )
        }
      }
      
      

      这样的代码编译也能通过

      发布在 Taro
      L
      lhuanyu123
    • taro下列表渲染的问题

      db9ebbcd-7984-4b10-8b64-88d0fe32a132-image.png
      求助,这句话怎么理解?只有在需要转成小程序的时候,这种方式进行列表渲染会出错?在h5下这样的方式编译时没问题的。

      发布在 Taro 实践 + 案例
      L
      lhuanyu123