当前位置:网站首页>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的值,达到重新渲染的效果
}
},
边栏推荐
- Spécifications techniques et lignes directrices pour la sélection des tubes TVS et ESD - Recommandation de jialichuang
- idea 连接mysql ,直接贴配置文件的url 比较方便
- UVA11294-Wedding(2-SAT)
- Différence entre hors bande et en bande
- How to improve eloquence
- Creative mode 1 - single case mode
- 【原创】程序员团队管理的核心是什么?
- 98. 验证二叉搜索树 ●●
- Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
- Brushless drive design -- on MOS drive circuit
猜你喜欢

Southeast Asia e-commerce guide, how do sellers layout the Southeast Asia market?

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

Do you regret becoming a programmer?

Fiddler Everywhere 3.2.1 Crack

【LeetCode】5. Valid Palindrome·有效回文

Switching power supply buck circuit CCM and DCM working mode

98. Verify the binary search tree ●●

Spécifications techniques et lignes directrices pour la sélection des tubes TVS et ESD - Recommandation de jialichuang

数学公式截图识别神器Mathpix无限使用教程

MySQL replace primary key delete primary key add primary key
随机推荐
JVM的简介
3D reconstruction of point cloud
Shell: operator
golang代码检查工具
Common static methods of math class
Spécifications techniques et lignes directrices pour la sélection des tubes TVS et ESD - Recommandation de jialichuang
Design and implementation of secsha system
698. 划分为k个相等的子集 ●●
Pyqt control part (I)
98. Verify the binary search tree ●●
Live tiktok shop 2022 latest gameplay card slot overseas live e-commerce new traffic
Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
保研笔记一 软件工程与计算卷二(1-7章)
poj 2762 Going from u to v or from v to u? (infer whether it is a weak link diagram)
Rasa 3.x 学习系列-Rasa 3.2.1 新版本发布
Rasa 3.x 学习系列-Rasa X 社区版(免费版) 更改
LeetCode——Add Binary
Naoqi robot summary 26
Data analysis - Thinking foreshadowing
Brushless drive design -- on MOS drive circuit