elementUI select组件使用详解
动态生成option选项 option选项绑定对应的文本值和value值 作为表单项目,新增、编辑功能 对选项改变后触发相关事件<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值写成字符串了,导致没效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。