2020-02-07 22:31:26 +08:00
# Opened Submenu
2020-02-28 19:57:52 +08:00
You can set `default-expanded-names` to make menu work in an uncontrolled manner or use `expanded-names` and `@expanded-names-change` to make it work in a controlled manner.
2019-12-31 11:36:13 +08:00
```html
< n-menu
2020-02-07 22:31:26 +08:00
v-model="activeName"
2020-02-28 19:57:52 +08:00
:default-expanded-names="defaultExpandedNames"
@expanded -names-change="handleExpandedNamesChange"
2020-02-07 22:31:26 +08:00
@select ="handleSelect"
>
< n-menu-item title = "Hear the Wind Sing" name = "hear-the-wind-sing" >
< template v-slot:icon >
< n-icon >
< book-icon / >
< / n-icon >
< / template >
< / n-menu-item >
< n-submenu title = "Pinball, 1973" name = "pinball-1973" disabled >
< template v-slot:icon >
< n-icon >
< book-icon / >
< / n-icon >
< / template >
< n-menu-item title = "Rat" name = "rat" / >
< / n-submenu >
< n-menu-item title = "A Wild Sheep Chase" name = "a-wild-sheep-chase" disabled >
< template v-slot:icon >
< n-icon >
< book-icon / >
< / n-icon >
< / template >
< / n-menu-item >
< n-submenu title = "Dance Dance Dance" name = "dance-dance-dance" >
< template v-slot:icon >
< n-icon >
< book-icon / >
< / n-icon >
< / template >
< n-menu-item-group title = "Characters" >
< n-menu-item title = "Narrator" name = "narrator" >
< template v-slot:icon >
< n-icon >
< person-icon / >
< / n-icon >
< / template >
< / n-menu-item >
< n-menu-item title = "Sheep Man" name = "sheep-man" >
< template v-slot:icon >
< n-icon >
< person-icon / >
< / n-icon >
< / template >
< / n-menu-item >
< / n-menu-item-group >
< n-submenu title = "Beverage" name = "beverage" >
< template v-slot:icon >
< n-icon >
< wine-icon / >
< / n-icon >
< / template >
< n-menu-item title = "Whisky" name = "whisky" / >
< / n-submenu >
< n-submenu title = "Food" name = "food" >
< n-menu-item title = "Sandwich" name = "sandwich" / >
< / n-submenu >
< n-menu-item title = "The past increases. The future recedes." name = "the-past-increases-the-future-recedes" / >
< / n-submenu >
2019-12-31 11:36:13 +08:00
< / n-menu >
```
```js
2020-02-07 22:31:26 +08:00
import bookIcon from 'naive-ui/lib/icons/book-outline'
import personIcon from 'naive-ui/lib/icons/person-outline'
import wineIcon from 'naive-ui/lib/icons/wine-outline'
2019-12-31 11:36:13 +08:00
export default {
2020-02-07 22:31:26 +08:00
components: {
bookIcon,
personIcon,
wineIcon
},
2019-12-31 11:36:13 +08:00
data () {
return {
2020-02-25 14:28:23 +08:00
defaultExpandedNames: ['dance-dance-dance', 'food'],
2020-02-07 22:31:26 +08:00
activeName: null
2019-12-31 11:36:13 +08:00
}
},
methods: {
2020-02-07 22:31:26 +08:00
handleSelect (value) {
this.$NMessage.info('Select: ' + JSON.stringify(value))
2019-12-31 11:36:13 +08:00
},
2020-02-25 14:28:23 +08:00
handleExpandedNamesChange (value) {
this.$NMessage.info('ExpandedNamesChange: ' + JSON.stringify(value))
2019-12-31 11:36:13 +08:00
}
}
2020-02-07 22:31:26 +08:00
}
2019-12-31 11:36:13 +08:00
```