使用trao trao-ui 的历程

本文介绍如何在Taro框架中修改组件样式,包括去除默认搜索按钮、使用图片资源、页面加载动画及响应式布局技巧。同时,提供解决ScrollView横向滚动与View不换行问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

修改trao-ui组件中的默认样式

搜索组件中我不想要搜索按钮

<AtSearchBar value={this.state.value}
             onChange={this.handleChange}
             className="searchNoBtn"

然后再全局样式中添加:我的就在app.less文件

.searchNoBtn {
  .at-search-bar__action {
    display: none !important;
  }
}

不能用函数组件 会提示react undefined

 const renderLabel = (list) => {
   return list.map(v => {
     return (
       <AtTag>{v}</AtTag>
     )
   })
 };

这么写会报错。
可以直接在class 里面对数组进行map

<View className="panel-main">
{
 historyList.map((item, i) => {
    return <AtTag key={i}
      {item}
    </AtTag>
  })
}
</View>

使用图片

直接将相对路径放在src属性中,不起作用,
需要先import进来,最好把图片放到服务器上,然后直接写http路径

错误写法:

<Image src="./images/front.png" />

正确写法:

import namedPng from './images/front.png'
...
<Image src={namedPng} />

当进入页面就请求数据

componentDidShow 对应微信小程序的 onShow 方法。

taro里面没有this.props.history属性。

参考文章

部分页面加载动画

this.state.loading ? <AtActivityIndicator mode='center' content='加载中...'/> : null

官网

切换tab

使用navigateToredirectTo会报错navigateTo:fail can not navigateTo a tabbar page

Taro.switchTab({
	url: '/pages/index/index',
})

ScrollView 微信小程序横向滚动

View不换行问题。横向滚动需要添加:

  1. 属性scrollX
  2. 父元素设置white-space: nowrap
  3. 子元素设置display: inline-block
<ScrollView
	className='scrollview'
	scrollX
	>
		<View className="scroll-item item-a">A</View>
		<View className="scroll-item item-b">B</View>
</ScrollView>

<style>
.scrollview {
    height: 200px;
    white-space: nowrap;
    .scroll-item {
      display: inline-block;
      width: 550px;
      height: 200px;
    }
    .item-a {
      background-color: red;
    }
    .item-b {
      background-color: black;
    }
  }
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值