iview select清空选择,iview中select组件使用总结

本文介绍了如何在Vue.js中使用iview的select组件进行远程搜索,详细解析了设置filterable、remote、remote-method和loading等属性的方法,并展示了远程搜索方法的实现。同时,文章探讨了两个联动Select组件的交互,特别是在选择一个Select时如何清空另一个Select的内容,通过设置ref和调用clearSingleSelect方法实现了这一功能。
摘要由CSDN通过智能技术生成

1.使用iview的select组件进行远程搜索

远程搜索需同时设置 filterable、remote、remote-method、loading 四个 props,其中 loading 用于控制是否正在搜索中,remote-method 是远程搜索的方法。

注意:需要给 Option 设置 key。

设置初始显示值,需设置 label 属性。

页面代码:

{{item.userName}}

参数值:

export default{

data () {return{

userInfo: {

userId:''},

userList: [],

loading2:false}

}

}

远程搜索的方法:

remoteMethod2 (query) {

let self= this

if(query) {

self.loading2= truelet params={

name: query

}this.$api.getUserList(params).then(function(res) {if(res.meta.success) {this.userList=res.data

}else{this.$Message.error(res.meta.message)

}

})this.loading2 = false}

2.两个联动select清空内容

我想要的效果是,当第一个select调用接口时清空第二个select,重新赋值第二个select,使用设置 null 是不能够实现的。

{{item.departmentName}}

{{item.userName}}

(1)为搜索框赋值的方法

checkSupplierInfo (query) {

this.userInfo.searchText =query

},

(2)选择部门调用的接口时清空用户select值

clearSingleSelect:清空单选项,仅在 clearable="true" 时有效

实现方式是为要清空的select设置ref="store",通过this.$refs.store.clearSingleSelect()实现清空操作

selectSupplierByOrgId (val) {

//清空select绑定值

this.$refs.store.clearSingleSelect()

//根据部门id查询用户

let das ={

departmentId: val

}

this.$api.queryUserListByDepartmentId(das).then(res =>{

if(res.meta.success) {

this.userList=res.data.userList

if (this.userList.length > 0) {

this.isAble = false // v-bind:disabled="isAble"设置select禁用启用} else{

this.isAble = true}

} else{

this.$Message.error(res.meta.message)

}

}).catch(err =>{

this.$Modal.error({

title: '用户获取失败',

content: err

})

})

},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值