1、iview 4.0.0的select组件支持手动新建条目,在 filterable 模式下,开启属性 allow-create 可以通过在输入框中输入文字来创建新的条目,新建条目必须push到下拉列表中,否则先选择下拉列表中选项,再手动输入,回车,submitchannel函数获取不到
filterable allow-create @on-create="channelCreate"
<template>
<Modal v-model="ChannelModalStatus" footer-hide width="600px;" @on-visible-change="statechange">
<Form ref="channelForm" :model="channelForm">
<div style="margin-top: 10px;">
<Select v-model="channel" clearable filterable allow-create @on-create="channelCreate" ref="store" @keydown.native.enter.prevent ="keyDownEvent">
<Option v-for="item in channellist" :key="item" :value="item">{{item}}</Option>
</Select>
</div>
<div class="footer" style="margin-top: 10px;text-align: center;">
<Button type="primary" @click="submitchannel('channelForm')">提交</Button>
</div>
</Form>
</Modal>
</template>
channelCreate(val) {
this.channel = val;
this.channellist.push(this.channel);
},
2、form组件中,手动输入后,回车页面刷新,select组件添加@keydown.native.enter.prevent ="keyDownEvent",定义一个空方法
//防止输入框输入内容按enter键刷新内容,写个空方法
keyDownEvent(){
}
3、模态框关闭再次打开,清空输入框选项,模态框定义一个函数
@on-visible-change="statechange",模态框显示状态发生变化时触发,select组件定义 ref="store",clearSingleSelect必须和clearable 配合使用
//关闭弹窗时再次打开清空输入框内容
statechange() {
this.$refs.store.clearSingleSelect()
},
网友评论