时间:2021-07-01 10:21:17 帮助过:8人阅读
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值写成字符串了,导致没效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。