DropMenu 下拉菜单
下拉菜单可用于列表筛选
引入
import { DropMenu } from 'mand-mobile'
Vue.component(DropMenu.name, DropMenu)
代码演示
基础下拉菜单 getSelectedValue(0)
<template>
<div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-0">
<md-drop-menu
ref="dropMenu0"
:data="data"
></md-drop-menu>
<div class="content">正文区域</div>
</div>
</template>
<script>
import {DropMenu, Dialog} from 'mand-mobile'
export default {
name: 'drop-menu-demo',
components: {
[DropMenu.name]: DropMenu,
},
data() {
return {
isContentShow: false,
data: [
{
text: '一级选项1',
options: [
{
text: '二级选项1',
},
{
text: '二级选项2',
},
],
},
],
}
},
mounted() {
window.DropMenuTrigger = () => {
this.getSelectedValue('dropMenu0', 0)
}
},
methods: {
getSelectedValue(selector, index) {
const value = this.$refs[selector].getSelectedValue(index)
Dialog.alert({
content: `<pre>${JSON.stringify(value)}</pre>`,
})
},
},
}
</script>
禁用下拉菜单
<template>
<div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-2">
<md-drop-menu
ref="dropMenu1"
:data="data"
:default-value="['1.8L', '自动挡']"
></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: '排量',
options: [
{
text: '1.6L',
},
{
text: '1.8L',
},
{
text: '2.0L',
disabled: true,
},
{
text: '1.2T',
},
{
text: '1.4T',
},
{
text: '1.6T',
},
],
},
{
text: '变速箱',
disabled: true,
},
],
}
},
}
</script>
初始下拉菜单
<template>
<div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-1">
<md-drop-menu
ref="dropMenu1"
:data="data"
:default-value="['1.8L', '自动挡']"
></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: '排量',
options: [
{
text: '1.6L',
},
{
text: '1.8L',
},
{
text: '2.0L',
},
{
text: '1.2T',
},
{
text: '1.4T',
},
{
text: '1.6T',
},
],
},
{
text: '变速箱',
options: [
{
text: '手动挡',
},
{
text: '自动挡',
},
{
text: '手自一体',
},
],
},
],
}
},
}
</script>
自定义菜单项
<template>
<div class="md-example-child md-example-child-drop-menu md-example-child-drop-menu-3">
<md-drop-menu
ref="dropMenu3"
: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, Dialog} from 'mand-mobile'
export default {
name: 'drop-menu-demo',
components: {
[DropMenu.name]: DropMenu,
},
data() {
return {
isContentShow: false,
data: [
{
text: '一级选项1',
options: [
{
text: '二级选项1',
},
{
text: '二级选项2',
},
],
},
],
}
},
methods: {
getSelectedValue(selector, index) {
const value = this.$refs[selector].getSelectedValue(index)
Dialog.alert({
content: `<pre>${JSON.stringify(value)}</pre>`,
})
},
},
}
</script>
<style lang="stylus">
.md-example-child-drop-menu-3
.md-drop-menu-custom-title
font-size 28px
.md-drop-menu-custom-brief
font-size 20px
color #999
</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()
下拉菜单隐藏事件