Even if there is a beforeUnmount hook, a warning of beforeDestroy appears.
Version
3.0.11
Reproduction link
Steps to reproduce
export default {
beforeDestroy() {
},
beforeUnmount() {
},
};
What is expected?
I use both beforeDestory and beforeUnmount to support Vue2 and Vue3 at the same time. If beforeUnmount has a hook, I hope that the beforeDestory warning does not appear.
What is actually happening?
beforeDestroy
has been renamed to beforeUnmount
.
as a workaround:
import * as Vue from 'vue'
const unmountKey = Vue.version > '3' ? 'beforeUnmount':'beforeDestroy'
export default {
[unmountKey]() {
console.log(Vue.version)
},
};
@edison1105
Since there is only default in vue2
import Vue from "vue";
It is used as Vue.version
.
If you use esm, a warning appears.
I recommend you to try this https://github.com/vueuse/vue-demi