JSFiddle - React, Tailwind, and code Playground
vue select例子
by ke zheng
HTML
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@2.4.6/lib/index.js"></script>
<div id="app">
<template>
<el-select v-model="value" placeholder="请选择" @change="change">
<el-option v-for="(item,index) in options" :key="item.value" :label="item.label" :value="index">
</el-option>
</el-select>
</template>
</div>
SCSS
@import url("//unpkg.com/element-ui@2.4.6/lib/theme-chalk/index.css");
Babel + JSX
var Main = {
methods:{
change(){
console.log(this.options[this.value])
}
},
data() {
return {
options: [{
value: '选项1',
label: '黄金糕'
}, {
value: '选项2',
label: '双皮奶'
}, {
value: '选项3',
label: '蚵仔煎'
}, {
value: '选项4',
label: '龙须面'
}, {
value: '选项5',
label: '北京烤鸭'
}],
value: ''
}
},
created(){
setTimeout(()=>{
this.options.forEach((item,index)=>{
if(item.value==='选项5'){
this.value=index
}
})
},1000)
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')