当前位置:网站首页>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的值,达到重新渲染的效果
}
},
边栏推荐
- orgchart. JS organization chart, presenting structural data in an elegant way
- STM32__ 06 - single channel ADC
- Comparison of parameters between TVs tube and zener diode
- Attacking technology Er - Automation
- UVA11294-Wedding(2-SAT)
- How to design API return code (error code)?
- grafana工具界面显示报错influxDB Error
- Do you regret becoming a programmer?
- 开关电源Buck电路CCM及DCM工作模式
- What is the process of building a website
猜你喜欢

MySQL delete uniqueness constraint unique

Object detection based on impulse neural network

Non rigid / flexible point cloud ICP registration

Go语言实现原理——Map实现原理

Rasa 3. X learning series -rasa x Community Edition (Free Edition) changes
![Development specification: interface unified return value format [resend]](/img/3e/8751b818147cabbe22e4ce44af7d24.jpg)
Development specification: interface unified return value format [resend]

orgchart. JS organization chart, presenting structural data in an elegant way

成为程序员的你,后悔了吗?

Dynamic memory management (malloc/calloc/realloc)

14种神笔记方法,只需选择1招,让你的学习和工作效率提高100倍!
随机推荐
98. 验证二叉搜索树 ●●
【经典控制理论】自控实验总结
poj 2762 Going from u to v or from v to u? (infer whether it is a weak link diagram)
TVS管 与 稳压二极管参数对比
VS2010编写动态链接库DLL和单元测试,转让DLL测试的正确性
[original] what is the core of programmer team management?
Calculating the number of daffodils in C language
MySQL delete uniqueness constraint unique
Initial experience | purchase and activate typora software
Opencvsharp (C openCV) shape detection and recognition (with source code)
保研笔记四 软件工程与计算卷二(8-12章)
Pyqt control part (I)
(4) UART application design and simulation verification 2 - RX module design (stateless machine)
Difference between out of band and in band
Why use weak pointers for delegation- Why use weak pointer for delegation?
Redis高可用——主从复制、哨兵模式、集群
698. Divided into k equal subsets ●●
ORB_ SLAM2/3
LabVIEW打开PNG 图像正常而 Photoshop打开得到全黑的图像
SpreadJS 15.1 CN 与 SpreadJS 15.1 EN