elementUI select組件使用詳解
<div id="app">
<el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">
<el-form-item label="姓名選擇" prop="typeId">
<el-select v-model="form.typeId" placeholder="請選擇" @change="change">
<el-option v-for="item in items" :label="item.name" :value="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="add()">新增</el-button>
<el-button type="primary" @click="edit()">編輯</el-button>
<el-button @click="cancel()">取消</el-button>
</el-form-item>
</el-form>
</div>
<script>
var vm = new Vue({
el:"#app",
mounted(){
this.getData();
},
data:{
form:{
typeId:''
},
items:[],
datas:[{name:"senbo",id:'1'},{name:"muse",id:'2'},{name:"bobo",id:'3'}]
},
methods:{
getData:function(){
this.items = this.datas;
},
add:function(){
this.form.typeId = "";
},
cancel(){
this.form.typeId = "";
},
change:function(){
console.log(this.form.typeId)
},
edit:function(){
this.form.typeId ="1";
}
}
})
</script>
當在使用select組件的時候,要注意
<el-select v-model="scope.row.state"
@change="editDriftStatus"
placeholder="請選擇">
<el-option v-for="item in drifStatusOptions"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
el-select 里面的v-model值要和el-option里面的value值對上,特別注意數據類型,之前value值寫成字符串了,導致沒效果
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。