Home >php教程 >PHP开发 >Detailed explanation of the bottom menu of WeChat applet action-sheet

Detailed explanation of the bottom menu of WeChat applet action-sheet

高洛峰
高洛峰Original
2016-12-08 15:49:032046browse

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

Detailed explanation of the bottom menu of WeChat applet action-sheet

.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 = [&#39;item1&#39;, &#39;item2&#39;, &#39;item3&#39;, &#39;item4&#39;]
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[&#39;bind&#39; + itemName] = function(e) {
   console.log(&#39;click&#39; + 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.

Detailed explanation of the bottom menu of WeChat applet action-sheet

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn