WeChat applet action-sheet
action-sheet is a selection menu that pops up from the bottom. The submenu is specified by action-sheet-item and action-sheet-cancel. action-sheet-item is the menu item and action-sheet-cancel As the name suggests, it is to unhide the menu. We can trigger the response after clicking by adding bindtap to action-sheet-item. When action-sheet-cancel is clicked, the bindchange event of action-sheet will be triggered. The display of the menu can be controlled in the function bound to bindchange. In addition, the menu will also be hidden when clicking on a blank space.
Official document
.wxml
<button type="default" bindtap="actionSheetTap">弹出action sheet</button> <action-sheet hidden="{{actionSheetHidden}}" bindchange="actionSheetChange"> <block wx:for-items="{{actionSheetItems}}"> <action-sheet-item bindtap="bind{{item}}">{{item}}</action-sheet-item> </block> <action-sheet-cancel >取消</action-sheet-cancel> </action-sheet>
.js
var items = ['item1', 'item2', 'item3', 'item4'] var pageObject = { data: { actionSheetHidden: true, actionSheetItems: items }, actionSheetTap: function(e) { console.log(this); this.setData({ actionSheetHidden: !this.data.actionSheetHidden }) }, actionSheetChange: function(e) { this.setData({ actionSheetHidden: !this.data.actionSheetHidden }); console.log("点击ation-sheet-cancel,会触发action-sheet绑定的事件。在这里可以通过改变hidden控制菜单的隐藏"); } } for (var i = 0; i < items.length; ++i) { (function(itemName) { pageObject['bind' + itemName] = function(e) { console.log('click' + itemName, e) } })(items[i]) } Page(pageObject)
How to get the running effect
How about not hiding the image when clicking on a blank space? In addition, instead of automatically hiding the menu when you click Cancel, you have to write a sentence to hide it, which is really troublesome.