微信小程序里 wx.showActionSheet 使用?

作者站长头像
站长
· 阅读数 16
<view bindtap="openActionsheet">打开 Actionsheet</view>
<view>data: </view>
Page({

     data: {

     },
     openActionsheet() {
          wx.showActionSheet({
               itemList: ['菜单1', '菜单2'],
               success(res) {
                    console.log(res)
                    this.setData({
                         data: res
                    })
               }
          })
     }

})

微信小程序里 wx.showActionSheet 使用?

选择后报了一个setData 未定义的错我需要在<view>data: </view>这里接收到选择的菜单, 应该如何实现?

回复
1个回答
avatar
test
2024-07-17
<view bindtap="openActionsheet">打开 Actionsheet</view>
<view>data: {{ res }}</view>
Page({

     data: {
        res: "",
     },
     openActionsheet() {
          const itemList = ['菜单1', '菜单2']; 
          wx.showActionSheet({
               itemList,
               success: (res) => {
                    console.log(res)
                    this.setData({
                         res: itemList[res.tapIndex]
                    })
               }
          })
     }

})

https://developers.weixin.qq....

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容