当前位置:网站首页>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的值,达到重新渲染的效果
}
},
边栏推荐
- Go language introduction detailed tutorial (I): go language in the era
- How to enable relationship view in phpMyAdmin - how to enable relationship view in phpMyAdmin
- 3:第一章:认识JVM规范2:JVM规范,简介;
- 20.移植Freetype字体库
- 证明 poj 1014 模优化修剪,部分递归 有错误
- 保研笔记一 软件工程与计算卷二(1-7章)
- ts类型声明declare
- 动态规划 之 打家劫舍
- Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
- 保研笔记二 软件工程与计算卷二(13-16章)
猜你喜欢

14种神笔记方法,只需选择1招,让你的学习和工作效率提高100倍!

Scala concurrent programming (II) akka

There are 14 God note taking methods. Just choose one move to improve your learning and work efficiency by 100 times!

动态规划 之 打家劫舍

CIS基准测试工具kube-bench使用
![[original] what is the core of programmer team management?](/img/11/d4b9929e8aadcaee019f656cb3b9fb.png)
[original] what is the core of programmer team management?

Do you regret becoming a programmer?

Pyqt control part (I)

From the perspective of quantitative genetics, why do you get the bride price when you get married

Neural structured learning - Part 3: training with synthesized graphs
随机推荐
(4) UART application design and simulation verification 2 - TX module design (stateless machine)
Golang code checking tool
How to insert data into MySQL database- How can I insert data into a MySQL database?
Do you regret becoming a programmer?
LeetCode——Add Binary
Rethinking about MySQL query optimization
代码农民提高生产力
Spire.PDF for NET 8.7.2
ORB_ SLAM2/3
数学公式截图识别神器Mathpix无限使用教程
asp.net弹出层实例
poj 2762 Going from u to v or from v to u? (推断它是否是一个薄弱环节图)
Switching power supply buck circuit CCM and DCM working mode
Go语言实现原理——Map实现原理
Sum of two numbers, sum of three numbers (sort + double pointer)
Rasa 3. X learning series -rasa x Community Edition (Free Edition) changes
98. 验证二叉搜索树 ●●
698. Divided into k equal subsets ●●
Opencvsharp (C openCV) shape detection and recognition (with source code)
3:第一章:认识JVM规范2:JVM规范,简介;