• 引入
  • 代码演示
    • 基础下拉菜单
    • 禁用下拉菜单
    • 初始下拉菜单
    • 自定义菜单项
  • API
    • DropMenu Props
    • DropMenu Methods
      • getSelectedValue(index): listItem
      • getSelectedValues(): listItems
    • DropMenu Events
      • @change(barItem, listItem)
      • @show()
      • @hide()

    DropMenu 下拉菜单

    Scan me!

    下拉菜单可用于列表筛选

    引入

    1. import { DropMenu } from 'mand-mobile'
    2. Vue.component(DropMenu.name, DropMenu)

    代码演示

    基础下拉菜单

    DropMenu 下拉菜单 - 图2

    1. <template>
    2. <div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-0">
    3. <md-drop-menu :data="data" />
    4. <div class="content">正文区域</div>
    5. </div>
    6. </template>
    7. <script>
    8. import {DropMenu} from 'mand-mobile'
    9. export default {
    10. name: 'drop-menu-demo',
    11. components: {
    12. [DropMenu.name]: DropMenu,
    13. },
    14. data() {
    15. return {
    16. data: [
    17. {
    18. text: '一级选项1',
    19. options: [
    20. {
    21. value: '0',
    22. text: '二级选项1',
    23. },
    24. {
    25. value: '1',
    26. text: '二级选项2',
    27. },
    28. ],
    29. },
    30. ],
    31. }
    32. },
    33. }
    34. </script>
    35.  

    禁用下拉菜单

    DropMenu 下拉菜单 - 图3

            <template>
      <div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-2">
        <md-drop-menu :data="data" :default-value="['1', '8']" />
        <div class="content">正文区域</div>
      </div>
    </template>
    
    <script>
    import {DropMenu} from 'mand-mobile'
    
    export default {
      name: 'drop-menu-demo',
      components: {
        [DropMenu.name]: DropMenu,
      },
      data() {
        return {
          isContentShow: false,
          data: [
            {
              text: '排量',
              options: [
                {
                  value: '0',
                  text: '1.6L',
                },
                {
                  value: '1',
                  text: '1.8L',
                },
                {
                  value: '2',
                  text: '2.0L',
                  disabled: true,
                },
                {
                  value: '3',
                  text: '1.2T',
                },
                {
                  value: '4',
                  text: '1.4T',
                },
                {
                  value: '5',
                  text: '1.6T',
                },
              ],
            },
            {
              text: '变速箱',
              disabled: true,
              options: [
                {
                  value: '7',
                  text: '手动挡',
                },
                {
                  value: '8',
                  text: '自动挡',
                },
                {
                  value: '9',
                  text: '手自一体',
                },
              ],
            },
          ],
        }
      },
    }
    
    </script>
    
          

    初始下拉菜单

    DropMenu 下拉菜单 - 图4

            <template>
      <div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-1">
        <md-drop-menu :data="data" :default-value="['1', '8']" />
        <div class="content">正文区域</div>
      </div>
    </template>
    
    <script>
    import {DropMenu} from 'mand-mobile'
    
    export default {
      name: 'drop-menu-demo',
      components: {
        [DropMenu.name]: DropMenu,
      },
      data() {
        return {
          isContentShow: false,
          data: [
            {
              text: '排量',
              options: [
                {
                  value: '0',
                  text: '1.6L',
                },
                {
                  value: '1',
                  text: '1.8L',
                },
                {
                  value: '2',
                  text: '2.0L',
                },
                {
                  value: '3',
                  text: '1.2T',
                },
                {
                  value: '4',
                  text: '1.4T',
                },
                {
                  value: '5',
                  text: '1.6T',
                },
              ],
            },
            {
              text: '变速箱',
              options: [
                {
                  value: '7',
                  text: '手动挡',
                },
                {
                  value: '8',
                  text: '自动挡',
                },
                {
                  value: '9',
                  text: '手自一体',
                },
              ],
            },
          ],
        }
      },
    }
    
    </script>
    
          

    自定义菜单项

    DropMenu 下拉菜单 - 图5

            <template>
      <div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-3">
        <md-drop-menu :data="data">
          <template slot-scope="{ option }">
            <div class="md-drop-menu-custom-title" v-text="option.text"></div>
            <div class="md-drop-menu-custom-brief">{{ option.text }}【可使用slot-scope进行自定义描述】</div>
          </template>
        </md-drop-menu>
        <div class="content">正文区域</div>
      </div>
    </template>
    
    <script>
    import {DropMenu} from 'mand-mobile'
    
    export default {
      name: 'drop-menu-demo',
      components: {
        [DropMenu.name]: DropMenu,
      },
      data() {
        return {
          isContentShow: false,
          data: [
            {
              text: '一级选项1',
              options: [
                {
                  value: '0',
                  text: '二级选项1',
                },
                {
                  value: '1',
                  text: '二级选项2',
                },
              ],
            },
          ],
        }
      },
    }
    
    </script>
    
    <style lang="stylus">
    .md-example-child-drop-menu-3
      .md-drop-menu-custom-title
        font-size 28px
        text-align center
      .md-drop-menu-custom-brief
        font-size 20px
        color #999
        text-align center
    </style>
    
          

    API

    DropMenu Props

    属性说明类型默认值备注
    data数据源Array<{text, disabled, options, …}>[]disabled为是否禁用,options类型为Array<{text, disabled, …}>
    default-value初始值Array[]-
    option-render返回各选项渲染内容Function({text, disabled, …}):String-vue 2.1.0+可使用slot-scope,参考Radio

    DropMenu Methods

    getSelectedValue(index): listItem

    获取某菜单项选中值

    参数说明类型默认值
    index菜单项索引值Number-

    返回

    属性说明类型
    listItem选项数据Object: {text, disabled, options, …}
    getSelectedValues(): listItems

    获取所有菜单项选中值

    返回

    属性说明类型
    listItems选项数据Array<{text, disabled, options, …}>

    DropMenu Events

    @change(barItem, listItem)

    选中某项事件

    属性说明类型
    barItem菜单项数据Object: {text, disabled, options, …}
    listItem选项数据Object: {text, disabled, …}
    @show()

    下拉菜单展示事件

    @hide()

    下拉菜单隐藏事件