代码:
<a-select
show-search
option-filter-prop="children"
:filter-option="filterOption"
placeholder="请选择!!!"
v-decorator="['id', { rules: [{ required: true, message: '请选择!' }] }]"
>
<a-select-option
v-for="item in dataList"
:key="item.id"
:value="item.id"
>
{{ item.name }}
</a-select-option>
</a-select>
如上,运行代码,其中的 placeholder="请选择!!!"
默认提示未显示。
解决:
// 编辑时的回显
showModal(record) {
this.visible = true;
this.editId = record.id
this.$nextTick(function () {
this.form.setFieldsValue({
name: record.name,
id: undefined, // 必须为undefined,placeholder默认显示才生效
})
// 请求接口
getdataList().then(res => {
if (res.statusCode === 200) {
this.dataList = res.data.dataList
}
})
})
},
如上,初始化时将id
设为 undefined
解决办法:
可能是antd本身的问题,a-select绑定的值初始为 " "
或为 null
都不行,初始必须设为 undefined
,才显示默认提示。