当前位置:网站首页>el-cascader的使用以及报错解决
el-cascader的使用以及报错解决
2022-07-05 23:26:00 【SwJieJie】
问题描述:
场景:有的类型没有数据,这时cascader的options是[ ],下拉框是空的。如果选择了一个类型,根据类型获取了cascader的数据,在cascader中选择了一条数据,再更换类型,没有这条数据了就会报错
这是在使用element ui中的cascader出现的报错
原因暂时不清楚,个人理解可能是因为数据源没得到及时更新,而vue是数据驱动的,所以我加了监听器,并且给cascader绑定了一个key,这样只要监听到数据源发生变化,key 就变化,就重新渲染
解决办法1:
如果没有数据就将cascader设置为不可编辑
<el-cascader
:options="cascaderOption"
:props="props"
:disabled="optionsChanged"
v-model="cascaderValue"
collapse-tags
:placeholder="showPlaceholder"
/>
并且直接return,不加载下拉节点
getCascader() {
this.cascaderValue= []
getCascader(this.type).then(response => {
if(response.data.data.length === 0){
this.optionsChanged = true
this.showPlaceholder = '暂无范围'
return
}
this.cascaderOption = response.data.data
});
}
解决办法2:通过绑定唯一的key,key 就变化,就重新渲染
<el-cascader
:key="keyValue" //keyValue在data中定义,初始值为0
clearable
:props="propsObj"
v-model="value"
:options="options"
>
</el-cascader>
watch: {
options(newVal) {
this.keyValue++ //只要监听到数据源发生变化 ,改变keyValue的值,达到重新渲染的效果
}
},
边栏推荐
- Spire.PDF for NET 8.7.2
- Naoqi robot summary 26
- TVS管 与 稳压二极管参数对比
- LeetCode——Add Binary
- 保研笔记二 软件工程与计算卷二(13-16章)
- Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
- CIS benchmark tool Kube bench
- Debian 10 installation configuration
- 有什么不起眼却挣钱的副业?
- From the perspective of quantitative genetics, why do you get the bride price when you get married
猜你喜欢
Dynamic planning: robbing families and houses
2: Chapter 1: understanding JVM specification 1: introduction to JVM;
Debian 10 installation configuration
基于脉冲神经网络的物体检测
Xinyuan & Lichuang EDA training camp - brushless motor drive
SpreadJS 15.1 CN 与 SpreadJS 15.1 EN
698. 划分为k个相等的子集 ●●
21.PWM应用编程
2:第一章:认识JVM规范1:JVM简介;
Initial experience | purchase and activate typora software
随机推荐
Switching power supply buck circuit CCM and DCM working mode
What is the process of building a website
2:第一章:认识JVM规范1:JVM简介;
VS2010编写动态链接库DLL和单元测试,转让DLL测试的正确性
Live tiktok shop 2022 latest gameplay card slot overseas live e-commerce new traffic
From the perspective of quantitative genetics, why do you get the bride price when you get married
Comparison between webgl and webgpu [3] - vertex buffer
MySQL replace primary key delete primary key add primary key
Data analysis - Thinking foreshadowing
进击的技术er——自动化
Cwaitabletimer timer, used to create timer object access
Xinyuan & Lichuang EDA training camp - brushless motor drive
Development specification: interface unified return value format [resend]
Attacking technology Er - Automation
开源crm客户关系统管理系统源码,免费分享
poj 2762 Going from u to v or from v to u? (infer whether it is a weak link diagram)
【经典控制理论】自控实验总结
MySQL delete uniqueness constraint unique
Déterminer si un arbre binaire est un arbre binaire complet
Brushless drive design -- on MOS drive circuit