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
<template id="rxselect"> | |
<select v-model="innerValue"> | |
<option | |
v-for="[k,v] in map" | |
:value="k" | |
:key="k" | |
>{{v}}</option> | |
</select> | |
</template> | |
<div id="app"> | |
The currently selected gender is: | |
{{map.get(gender)}} | |
<div> | |
<rx-select :map="map" v-model="gender" /> | |
</div> |
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
Vue.component("RxSelect", { | |
model: { | |
prop: "value", | |
event: "change", | |
}, | |
props: { | |
value: [Number, String], | |
map: Map, | |
}, | |
computed: { | |
innerValue: { | |
get() { | |
return this.value; | |
}, | |
set(val) { | |
this.$emit("change", val); | |
}, | |
}, | |
}, | |
template: "#rxselect" | |
}); | |
new Vue({ | |
el: "#app", | |
data: { | |
map: new Map().set(1, "Keep secret").set(2, "Male").set(3, "Female"), | |
gender: "", | |
}, | |
}); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.6.6/rxjs.umd.min.js"></script> |
A Pen by Edward Lance Lorilla on CodePen.
No comments:
Post a Comment