Fix the memory leak of Select component
This commit is contained in:
parent
403a4f7c2c
commit
6ee13b133a
4 changed files with 33 additions and 16 deletions
|
@ -110,8 +110,11 @@
|
||||||
this.$on('on-destroy-popper', this.destroy);
|
this.$on('on-destroy-popper', this.destroy);
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
|
this.$off('on-update-popper', this.update);
|
||||||
|
this.$off('on-destroy-popper', this.destroy);
|
||||||
if (this.popper) {
|
if (this.popper) {
|
||||||
this.popper.destroy();
|
this.popper.destroy();
|
||||||
|
this.popper = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const returnArrayFn = () => [];
|
const returnArrayFn = () => [];
|
||||||
|
|
||||||
|
@ -15,15 +14,19 @@
|
||||||
slotUpdateHook: {
|
slotUpdateHook: {
|
||||||
type: Function,
|
type: Function,
|
||||||
default: () => {}
|
default: () => {}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
functional: true,
|
// if use functional, there will be memory leaks
|
||||||
render(h, {props, parent}){
|
// functional: true,
|
||||||
|
render(h) {
|
||||||
// to detect changes in the $slot children/options we do this hack
|
// to detect changes in the $slot children/options we do this hack
|
||||||
// so we can trigger the parents computed properties and have everything reactive
|
// so we can trigger the parents computed properties and have everything reactive
|
||||||
// although $slot.default is not
|
// although $slot.default is not
|
||||||
if (props.slotOptions !== parent.$slots.default) props.slotUpdateHook();
|
if (this.slotOptions !== this.$parent.$slots.default) this.slotUpdateHook();
|
||||||
return props.options;
|
return h('ul', [
|
||||||
|
this.$slots.default,
|
||||||
|
this.options
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -43,6 +43,9 @@
|
||||||
this.queryChange();
|
this.queryChange();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.$off('on-query-change');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -22,10 +22,8 @@
|
||||||
@keydown.tab="handleKeydown"
|
@keydown.tab="handleKeydown"
|
||||||
@keydown.delete="handleKeydown"
|
@keydown.delete="handleKeydown"
|
||||||
|
|
||||||
|
|
||||||
@mouseenter="hasMouseHoverHead = true"
|
@mouseenter="hasMouseHoverHead = true"
|
||||||
@mouseleave="hasMouseHoverHead = false"
|
@mouseleave="hasMouseHoverHead = false"
|
||||||
|
|
||||||
>
|
>
|
||||||
<slot name="input">
|
<slot name="input">
|
||||||
<input type="hidden" :name="name" :value="publicValue">
|
<input type="hidden" :name="name" :value="publicValue">
|
||||||
|
@ -67,18 +65,26 @@
|
||||||
v-transfer-dom
|
v-transfer-dom
|
||||||
>
|
>
|
||||||
<ul v-show="showNotFoundLabel && !allowCreate" :class="[prefixCls + '-not-found']"><li>{{ localeNotFoundText }}</li></ul>
|
<ul v-show="showNotFoundLabel && !allowCreate" :class="[prefixCls + '-not-found']"><li>{{ localeNotFoundText }}</li></ul>
|
||||||
<ul :class="prefixCls + '-dropdown-list'">
|
|
||||||
|
<functional-options
|
||||||
|
v-if="(!remote) || (remote && !loading)"
|
||||||
|
:options="selectOptions"
|
||||||
|
:slot-update-hook="updateSlotOptions"
|
||||||
|
:slot-options="slotOptions"
|
||||||
|
:class="prefixCls + '-dropdown-list'"
|
||||||
|
>
|
||||||
|
<li :class="prefixCls + '-item'" v-if="showCreateItem" @click="handleCreateItem">
|
||||||
|
{{ query }}
|
||||||
|
<Icon type="md-return-left" :class="prefixCls + '-item-enter'" />
|
||||||
|
</li>
|
||||||
|
</functional-options>
|
||||||
|
<ul :class="prefixCls + '-dropdown-list'" v-else>
|
||||||
<li :class="prefixCls + '-item'" v-if="showCreateItem" @click="handleCreateItem">
|
<li :class="prefixCls + '-item'" v-if="showCreateItem" @click="handleCreateItem">
|
||||||
{{ query }}
|
{{ query }}
|
||||||
<Icon type="md-return-left" :class="prefixCls + '-item-enter'" />
|
<Icon type="md-return-left" :class="prefixCls + '-item-enter'" />
|
||||||
</li>
|
</li>
|
||||||
<functional-options
|
|
||||||
v-if="(!remote) || (remote && !loading)"
|
|
||||||
:options="selectOptions"
|
|
||||||
:slot-update-hook="updateSlotOptions"
|
|
||||||
:slot-options="slotOptions"
|
|
||||||
></functional-options>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul v-show="loading" :class="[prefixCls + '-loading']">{{ localeLoadingText }}</ul>
|
<ul v-show="loading" :class="[prefixCls + '-loading']">{{ localeLoadingText }}</ul>
|
||||||
</Drop>
|
</Drop>
|
||||||
</transition>
|
</transition>
|
||||||
|
@ -317,8 +323,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
this.$off('on-select-selected');
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
values: [],
|
values: [],
|
||||||
|
|
Loading…
Add table
Reference in a new issue