第一种情况:
el-select动态获取数据, 默认选中第一个
<el-select
v-model="formData.operator_id"
placeholder="请选择"
class="filter-item"
style="width: 130px">
<el-option
v-for="item in operatorLists"
:key=""
:label="item.operator_name"
:value=""/>
</el-select>
.operator_id = [0].id 这句要加在动态获取了列表之后,如下:
OperatorSelect() {
this.operatorSelect()
.then(res => {
this.operatorLists=res.data
this.formData.operator_id = this.operatorLists[0].id
})
.catch(err => {
this.$message.error(err.message)
})
},
第二种情况:
el-select静态获取数据, 默认选中第一个
<el-select
v-model=""
placeholder="请选择"
class="filter-item"
style="width: 130px">
<el-option
v-for="item in statusLists"
:key=""
:label="item.status_name"
:value="" />
</el-select>
data() {
return {
statusLists:[{id:1,status_name:'上线'},{id:2,status_name:'下线'}]
}
},
created() {
this.formData.status = this.statusLists[0].id
},