Cascader support loadData async
This commit is contained in:
parent
13a940ee86
commit
f7ffdac569
4 changed files with 71 additions and 15 deletions
|
@ -88,6 +88,9 @@
|
|||
default (label) {
|
||||
return label.join(' / ');
|
||||
}
|
||||
},
|
||||
loadData: {
|
||||
type: Function
|
||||
}
|
||||
},
|
||||
data () {
|
||||
|
@ -224,8 +227,11 @@
|
|||
}
|
||||
this.updateSelected(true);
|
||||
},
|
||||
data () {
|
||||
this.$nextTick(() => this.updateSelected());
|
||||
data: {
|
||||
deep: true,
|
||||
handler () {
|
||||
this.$nextTick(() => this.updateSelected());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<template>
|
||||
<li :class="classes">{{ data.label }}<i v-if="data.children && data.children.length" class="ivu-icon ivu-icon-ios-arrow-right"></i></li>
|
||||
<li :class="classes">
|
||||
{{ data.label }}
|
||||
<i v-if="showArrow" class="ivu-icon ivu-icon-ios-arrow-right"></i>
|
||||
<i v-if="showLoading" class="ivu-icon ivu-icon-load-c ivu-load-loop"></i>
|
||||
</li>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
|
@ -18,6 +22,12 @@
|
|||
[`${this.prefixCls}-menu-item-disabled`]: this.data.disabled
|
||||
}
|
||||
];
|
||||
},
|
||||
showArrow () {
|
||||
return (this.data.children && this.data.children.length) || ('loading' in this.data && !this.data.loading);
|
||||
},
|
||||
showLoading () {
|
||||
return 'loading' in this.data && this.data.loading;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<script>
|
||||
import Casitem from './casitem.vue';
|
||||
import Emitter from '../../mixins/emitter';
|
||||
import { findComponentUpward } from '../../utils/assist';
|
||||
|
||||
export default {
|
||||
name: 'Caspanel',
|
||||
|
@ -56,6 +57,16 @@
|
|||
handleTriggerItem (item, fromInit = false) {
|
||||
if (item.disabled) return;
|
||||
|
||||
if (item.loading !== undefined && !item.children.length) {
|
||||
const cascader = findComponentUpward(this, 'Cascader');
|
||||
if (cascader && cascader.loadData) {
|
||||
cascader.loadData(item, () => {
|
||||
this.handleTriggerItem(item);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// return value back recursion // 向上递归,设置临时选中值(并非真实选中)
|
||||
const backItem = this.getBaseItem(item);
|
||||
this.tmpItem = backItem;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue