Explorar o código

polish: warn deprecated beforeDestroy/destroyed lifecycle hooks (#1999)

Haoqun Jiang %!s(int64=5) %!d(string=hai) anos
pai
achega
c65d6def84
Modificáronse 1 ficheiros con 16 adicións e 0 borrados
  1. 16 0
      packages/runtime-core/src/componentOptions.ts

+ 16 - 0
packages/runtime-core/src/componentOptions.ts

@@ -316,7 +316,11 @@ interface LegacyOptions<
   updated?(): void
   activated?(): void
   deactivated?(): void
+  /** @deprecated use `beforeUnmount` instead */
+  beforeDestroy?(): void
   beforeUnmount?(): void
+  /** @deprecated use `unmounted` instead */
+  destroyed?(): void
   unmounted?(): void
   renderTracked?: DebuggerHook
   renderTriggered?: DebuggerHook
@@ -393,7 +397,9 @@ export function applyOptions(
     updated,
     activated,
     deactivated,
+    beforeDestroy,
     beforeUnmount,
+    destroyed,
     unmounted,
     render,
     renderTracked,
@@ -631,9 +637,19 @@ export function applyOptions(
   if (renderTriggered) {
     onRenderTriggered(renderTriggered.bind(publicThis))
   }
+  if (__DEV__ && beforeDestroy) {
+    warn(
+      `\`beforeDestroy\` has been renamed to \`beforeUnmount\`.`
+    )
+  }
   if (beforeUnmount) {
     onBeforeUnmount(beforeUnmount.bind(publicThis))
   }
+  if (__DEV__ && destroyed) {
+    warn(
+      `\`destroyed\` has been renamed to \`unmounted\`.`
+    )
+  }
   if (unmounted) {
     onUnmounted(unmounted.bind(publicThis))
   }