yinggcy
V2EX  ›  Vue.js

vue keep-alive 组件的共用组件被销毁

  •  
  •   yinggcy · May 13, 2021 · 2191 views
    This topic created in 1828 days ago, the information mentioned may be changed or developed.

    router-view 的组件 A 和 B 共用一个组件 C,C 组件有个插槽,A 在 C 中插入了 D 组件。

    经过测试,在 AB 组件中切换时,C 组件会执行 beforeDestroy 钩子,但 A 和 B 和 D 组件的钩子函数都不会重新执行。

    如何不然 C 组件销毁? 谢谢!

    3 replies    2021-05-13 11:15:53 +08:00
    yinggcy
        1
    yinggcy  
    OP
       May 13, 2021
    试了下给 C 组件加 keep-alive,beforeDestroy 不会被触发,但是在 AB 组件间切换还会触发 created,mounted 等钩子
    GressJoe
        2
    GressJoe  
       May 13, 2021
    activated,deactivated?
    yinggcy
        3
    yinggcy  
    OP
       May 13, 2021
    @GressJoe 不是, 按道理说 created,mounted 等钩子函数整个生命周期应该只能触发一次, 但是因为 keep-alive 失效导致多次触发了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5948 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 02:14 · PVG 10:14 · LAX 19:14 · JFK 22:14
    ♥ Do have faith in what you're doing.