Last active
July 11, 2019 18:26
-
-
Save cristijora/89204558c7c880fdd079f20756609663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dropdown.vue (parent) | |
<template> | |
<div> | |
<button @click="showMenu = !showMenu">Click me</button> | |
<dropdown-menu v-if="showMenu" :items="items" @select-option="onOptionSelected"></dropdown-menu> | |
</div> | |
<template> | |
<script> | |
export default { | |
props: { | |
items: Array | |
}, | |
data() { | |
return { | |
selectedOption: null, | |
showMenu: false | |
} | |
}, | |
methods: { | |
onOptionSelected(option) { | |
this.selectedOption = option | |
this.showMenu = true | |
} | |
} | |
} | |
</script> | |
// DropdownMenu.vue (child) | |
<template> | |
<ul> | |
<li v-for="item in items" @click="selectOption(item)">{{item.name}}</li> | |
</ul> | |
<template> | |
<script> | |
export default { | |
props: { | |
items: Array | |
}, | |
methods: { | |
selectOption(item) { | |
this.$emit('select-option', item) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment