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

<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
                    })
               }
          })
     }

})

image.png

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

阅读 2.1k
1 个回答
<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....

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题