taro框架之taro-ui中AtSwipeAction的使用

题记:所需效果:滑动删除

工作进程

官网文档代码

javascript 复制代码
<AtSwipeAction options={[
  {
    text: '取消',
    style: {
      backgroundColor: '#6190E8'
    }
  },
  {
    text: '确认',
    style: {
      backgroundColor: '#FF4949'
    }
  }
]}>
  <View className='normal'>AtSwipeAction 一般使用场景</View>
</AtSwipeAction>

发现写了没有效果,需要增加两个属性

maxDistance、areaWidth

javascript 复制代码
<AtSwipeAction 
  maxDistance={80}  
 areaWidth={Taro.getSystemInfoSync().windowWidth*0.88} // 适配不同手机系统屏幕宽度
 
  options={[
  {
    text: '取消',
    style: {
      backgroundColor: '#6190E8'
    }
  },
  {
    text: '确认',
    style: {
      backgroundColor: '#FF4949'
    }
  }
]}>
  <View className='normal'>AtSwipeAction 一般使用场景</View>
</AtSwipeAction>

还要注意<AtSwipeAction> 父组件的定位不要为 absolute ,这个是非常重要的。

下边是工作的一个案例代码

javascript 复制代码
{
                        showList.length>0?
                        showList.map((item) => {
                            return(
                                <View className='mainBoxItem' key={item.time}>
                                    <AtSwipeAction
                                        autoClose
                                        maxDistance={80}  
                                        areaWidth={Taro.getSystemInfoSync().windowWidth*0.88}
                                        options={[
                                        {
                                            text: '删除',
                                            style: {
                                                backgroundColor: '#FF4949'
                                            }
                                        }
                                        ]}
                                        onClick={this.deleteClick.bind(this,item)}
                                    >
                                        <View className='normal' onClick={this.subscribeDetail.bind(this,item)}>
                                            <View className='boxItem'>
                                                {
                                                    item.resourceImgs === null ?
                                                    <View className='imageBox1'>暂无图片</View>:
                                                    <Image className='imageBox' src={item.resourceImgs} />
                                                }
                                                <View className='content'>
                                                    <View className='contentTop'>{item.resourceTypes}</View>
                                                    <View className='contentBottom'>预约日期:{item.appointTime}</View>
                                                </View>
                                                <View className='contentFix' style={{background:item.changeColor}}>{item.statusContent}</View>
                                            </View>
                                        </View>
                                    </AtSwipeAction>
                                </View>
                            )
                        })
                        : 
                        <View className='none'>
                            <View  className='img' >
                                <Image src={none} className='pic'></Image>
                            </View>
                            <View className='noText'>暂无数据</View>
                        </View>
                    }

接下来的属性的介绍

isOpened

是否开启 Boolean 默认值:true

disabled

是否禁止滑动 Boolean 默认值:false

autoClose

点击选项时,是否自动关闭 Boolean 默认值:false

options

展示的选项数组 [{ text , style? , className? }] []

onClick

点击触发事件

onOpened

完全打开时触发

onClosed

完全关闭时触发

相关推荐
大米饭消灭者4 天前
Taro是怎么实现一码多端的【底层原理】
微信小程序·taro
Dragon Wu7 天前
记一次Taro v4集成tailwindcss踩坑
javascript·小程序·taro
GISer_Jing8 天前
Taro全栈学习路线与实战指南:从基础语法到工程化、性能优化深度进阶
前端·react.js·taro
GISer_Jing8 天前
从零到架构师:Taro 全链路学习与实战指南
前端·react.js·taro
GISer_Jing13 天前
Taro多端开发
前端·react.js·taro
光影少年17 天前
前端工程化
前端·webpack·taro
GISer_Jing18 天前
Taro 5.0 深度:跨端开发的架构革新与全阶实践指南
前端·react.js·taro
GISer_Jing18 天前
Taro 5.0 小白快速上手指南:从0到1实现跨端开发
前端·react.js·taro
光影少年1 个月前
AIGC + Taro / 小程序
小程序·aigc·taro
菜鸟una1 个月前
【微信小程序+Taro 3+NutUI 3】input (nut-input) 、 textarea (nut-texteare)类型使用避坑
前端·vue.js·微信小程序·小程序·taro