Sheet上拉菜单

    引入

    在app.json或index.json中引入组件,默认为ES6版本

    1. "usingComponents": {
    2. "vtu-sheet": "/miniprogram_npm/vtuweapp/sheet/vtu-sheet"
    3. }

    代码演示

    基础用法

    1. <vtu-btn type="primary" bind:click="showSheet1">弹出菜单</vtu-btn>
    2. <vtu-sheet show="{{show1}}" sheetList="{{sheetList1}}" bind:select="bindSelect1"></vtu-sheet>
    3. Page({
    4. data: {
    5. show1: false,
    6. sheetList1: [
    7. {
    8. label: '选项(异步)',
    9. desc: '确定删除吗?删除后无法恢复哦~',
    10. loading: false,
    11. async: true
    12. },
    13. {
    14. label: '禁用选项',
    15. disabled: true
    16. },
    17. {
    18. label: '删除',
    19. color: 'red',
    20. loading: false,
    21. icon: 'iconfont icon-picture-delet'
    22. }
    23. ]
    24. },
    25. showSheet1: function() {
    26. this.setData({
    27. show1: true
    28. })
    29. },
    30. bindSelect1: function(e) {
    31. let self = this
    32. let index = e.detail.index;
    33. switch (index) {
    34. case 0:
    35. setTimeout(function() {
    36. self.setData({
    37. show1: false
    38. })
    39. }, 1000)
    40. break;
    41. case 2:
    42. setTimeout(function() {
    43. self.setData({
    44. show1: false
    45. })
    46. }, 1000)
    47. break;
    48. }
    49. }
    50. });
    51.  

    微信开放能力

    <vtu-btn type="primary" bind:click="showSheet2">弹出菜单</vtu-btn>
    <vtu-sheet show="{{show2}}" sheetList="{{sheetList2}}" bind:getuserinfo="getUserInfo" bind:getphonenumber="getPhoneNumber"></vtu-sheet>
    
    Page({
      data: {
        show2: false,
        sheetList2: [
          {
            label: '分享',
            openType: 'share',
            icon: 'iconfont icon-share'
          },
          {
            label: '注册账号',
            openType: 'getUserInfo'
          },
          {
            label: '注册手机号',
            openType: 'getPhoneNumber'
          },
          {
            label: '打开客服',
            openType: 'contact'
          },
          {
            label: '打开授权设置页',
            openType: 'openSetting'
          },
          {
            label: '意见反馈',
            openType: 'feedback'
          }
        ]
      },
    
      showSheet2: function() {
        this.setData({
          show2: true
        })
      },
    
      getUserInfo: function(e) {
        wx.showToast({
          title: "获取用户信息成功!",
          icon: 'none',
          duration: 2000
        });
        console.log("getUserInfo: ", e)
      },
    
      getPhoneNumber: function(e) {
        wx.showToast({
          title: "获取用户手机号成功!",
          icon: 'none',
          duration: 2000
        });
        console.log("getPhoneNumber: ", e)
      }
    });
    
          

    组件参数

    Props

    参数说明类型默认值必填
    show下拉菜单是否显示Booleanfalse
    closeOnClickOverlay点击遮罩是否关闭菜单Booleantrue
    show-overlay是否显示遮罩层Booleantrue
    show-cancel是否显示取消按钮Booleantrue
    cancel-label取消按钮文案String取消
    sheet-list上拉菜单按钮列表Array-

    SheetList Props

    按钮属性参数

    参数说明类型默认值必填
    label按钮文字String-
    desc按钮描述String-
    loading加载状态Booleanfalse
    async是否异步Booleanfalse
    disabled是否禁用Booleanfalse
    color按钮文字颜色String-
    openType开放能力,具体参考微信开放文档String-

    Events

    事件说明返回值
    bind:select菜单点击事件event.detail = {index},index为选择按钮索引
    bind:getuserinfo用户点击该按钮时,会返回获取到的用户信息, 从返回参数的 detail 中获取到的值同 wx.getUserInfo同 wx.getUserInfo
    bind:getphonenumber获取用户手机号回调同 wx.getphonenumber
    bind:contact客服消息回调同 wx.contact
    bind:error当使用开放能力时,发生错误的回调同 wx.error
    bind:opensetting在打开授权设置页后回调同 wx.opensetting
    bind:launchapp打开 APP 成功的回调,open-type=launchApp时有效同 wx.launchapp

    外部样式类

    外部样式类名说明
    v-class组件外部样式类

    Sheet 上拉菜单 - 图1