【问题标题】:How to use activated and deactivated in vue composition api?如何在 vue composition api 中使用激活和停用?
【发布时间】:2020-08-25 15:51:50
【问题描述】:

如何在 vue 组合 api 中使用 activateddeactivated 保持活动事件?

我找不到任何参考资料in the docs

【问题讨论】:

  • 我认为你仍然可以在 vue 2/3 中使用 keep-alive activated/deactivated - 并且认为它可能超出了组合 API 的范围
  • there's onActivated – 当一个存活组件被激活时调用 onDeactivated – 当一个存活组件被禁用生命周期钩子时调用

标签: vue.js vue-composition-api


【解决方案1】:

对于 vue 组合 api - 您仍然可以访问 vue 中的 activated/deactivated 生命周期方法,包括在 vue-next 中。

vue.js 3/(beta)


我相信库 vue-composition-api 支持激活/停用方法,但未添加到文档中。

vue-composition-api

import {onActivated, onDeactivated} from "vue"

export default {
  setup() {
    onActivated(() => {
      // ... 
    })
    onDeactivated(() => {
      // ... 
    })
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-03
    • 2023-02-17
    • 2021-08-28
    • 2020-04-09
    • 2020-11-26
    • 1970-01-01
    • 2022-11-28
    • 2020-03-30
    相关资源
    最近更新 更多