DropMenu 下拉菜单

Scan me!

下拉菜单可用于列表筛选

引入

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

代码演示

基础下拉菜单 getSelectedValue(0)

  1. <template>
  2. <div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-0">
  3. <md-drop-menu
  4. ref="dropMenu0"
  5. :data="data"
  6. ></md-drop-menu>
  7. <div class="content">正文区域</div>
  8. </div>
  9. </template>
  10. <script>
  11. import {DropMenu, Dialog} from 'mand-mobile'
  12. export default {
  13. name: 'drop-menu-demo',
  14. components: {
  15. [DropMenu.name]: DropMenu,
  16. },
  17. data() {
  18. return {
  19. isContentShow: false,
  20. data: [
  21. {
  22. text: '一级选项1',
  23. options: [
  24. {
  25. text: '二级选项1',
  26. },
  27. {
  28. text: '二级选项2',
  29. },
  30. ],
  31. },
  32. ],
  33. }
  34. },
  35. mounted() {
  36. window.DropMenuTrigger = () => {
  37. this.getSelectedValue('dropMenu0', 0)
  38. }
  39. },
  40. methods: {
  41. getSelectedValue(selector, index) {
  42. const value = this.$refs[selector].getSelectedValue(index)
  43. Dialog.alert({
  44. content: `<pre>${JSON.stringify(value)}</pre>`,
  45. })
  46. },
  47. },
  48. }
  49. </script>

禁用下拉菜单

  1. <template>
  2. <div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-2">
  3. <md-drop-menu
  4. ref="dropMenu1"
  5. :data="data"
  6. :default-value="['1.8L', '自动挡']"
  7. ></md-drop-menu>
  8. <div class="content">正文区域</div>
  9. </div>
  10. </template>
  11. <script>
  12. import {DropMenu} from 'mand-mobile'
  13. export default {
  14. name: 'drop-menu-demo',
  15. components: {
  16. [DropMenu.name]: DropMenu,
  17. },
  18. data() {
  19. return {
  20. isContentShow: false,
  21. data: [
  22. {
  23. text: '排量',
  24. options: [
  25. {
  26. text: '1.6L',
  27. },
  28. {
  29. text: '1.8L',
  30. },
  31. {
  32. text: '2.0L',
  33. disabled: true,
  34. },
  35. {
  36. text: '1.2T',
  37. },
  38. {
  39. text: '1.4T',
  40. },
  41. {
  42. text: '1.6T',
  43. },
  44. ],
  45. },
  46. {
  47. text: '变速箱',
  48. disabled: true,
  49. },
  50. ],
  51. }
  52. },
  53. }
  54. </script>

初始下拉菜单

  1. <template>
  2. <div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-1">
  3. <md-drop-menu
  4. ref="dropMenu1"
  5. :data="data"
  6. :default-value="['1.8L', '自动挡']"
  7. ></md-drop-menu>
  8. <div class="content">正文区域</div>
  9. </div>
  10. </template>
  11. <script>
  12. import {DropMenu} from 'mand-mobile'
  13. export default {
  14. name: 'drop-menu-demo',
  15. components: {
  16. [DropMenu.name]: DropMenu,
  17. },
  18. data() {
  19. return {
  20. isContentShow: false,
  21. data: [
  22. {
  23. text: '排量',
  24. options: [
  25. {
  26. text: '1.6L',
  27. },
  28. {
  29. text: '1.8L',
  30. },
  31. {
  32. text: '2.0L',
  33. },
  34. {
  35. text: '1.2T',
  36. },
  37. {
  38. text: '1.4T',
  39. },
  40. {
  41. text: '1.6T',
  42. },
  43. ],
  44. },
  45. {
  46. text: '变速箱',
  47. options: [
  48. {
  49. text: '手动挡',
  50. },
  51. {
  52. text: '自动挡',
  53. },
  54. {
  55. text: '手自一体',
  56. },
  57. ],
  58. },
  59. ],
  60. }
  61. },
  62. }
  63. </script>

自定义菜单项

  1. <template>
  2. <div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-3">
  3. <md-drop-menu
  4. ref="dropMenu3"
  5. :data="data"
  6. >
  7. <template slot-scope="{ option }">
  8. <div class="md-drop-menu-custom-title" v-text="option.text"></div>
  9. <div class="md-drop-menu-custom-brief">{{ option.text }}【可使用slot-scope进行自定义描述】</div>
  10. </template>
  11. </md-drop-menu>
  12. <div class="content">正文区域</div>
  13. </div>
  14. </template>
  15. <script>
  16. import {DropMenu, Dialog} from 'mand-mobile'
  17. export default {
  18. name: 'drop-menu-demo',
  19. components: {
  20. [DropMenu.name]: DropMenu,
  21. },
  22. data() {
  23. return {
  24. isContentShow: false,
  25. data: [
  26. {
  27. text: '一级选项1',
  28. options: [
  29. {
  30. text: '二级选项1',
  31. },
  32. {
  33. text: '二级选项2',
  34. },
  35. ],
  36. },
  37. ],
  38. }
  39. },
  40. methods: {
  41. getSelectedValue(selector, index) {
  42. const value = this.$refs[selector].getSelectedValue(index)
  43. Dialog.alert({
  44. content: `<pre>${JSON.stringify(value)}</pre>`,
  45. })
  46. },
  47. },
  48. }
  49. </script>
  50. <style lang="stylus">
  51. .md-example-child-drop-menu-3
  52. .md-drop-menu-custom-title
  53. font-size 28px
  54. .md-drop-menu-custom-brief
  55. font-size 20px
  56. color #999
  57. </style>

API

DropMenu Props

属性说明类型默认值备注
data数据源Array<{text, disabled, options, …}>[]disabled为是否禁用,options类型为Array<{text, disabled, …}>
defaultValue初始值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()

下拉菜单隐藏事件