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>
當(dāng)在使用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值對上,特別注意數(shù)據(jù)類型,之前value值寫成字符串了,導(dǎo)致沒效果
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答