要為select設定默認值,有兩個步驟
1、數據中,聲明一個變量param;該變量的值設為你想設定的select option中value
2、控件的 v-model 綁定 param 即可
<div id="app"> <template> <el-select v-model="value4" clearable placeholder="請選擇"> <el-option v-for="item in options" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </div>
var Main = {
data() {
return {
options: [{
value: '選項1',
label: '黃金糕'
}, {
value: '選項2',
label: '雙皮奶'
}, {
value: '選項3',
label: '蚵仔煎'
}, {
value: '選項4',
label: '龍須面'
}, {
value: '選項5',
label: '北京烤鴨'
}],
value4: '選項2'
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
代碼摘自:https://segmentfault.com/q/1010000008962854