tina icon indicating copy to clipboard operation
tina copied to clipboard

组件没法使用新的lifetimes生命周期字段

Open callmesoul opened this issue 6 years ago • 0 comments

定义生命周期方法 生命周期方法可以直接定义在 Component 构造器的第一级参数中。

自小程序基础库版本 2.2.3 起,组件的的生命周期也可以在 lifetimes 字段内进行声明(这是推荐的方式,其优先级最高)。

代码示例:

Component({
  lifetimes: {
    attached() {
      // 在组件实例进入页面节点树时执行
    },
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  // 以下是旧式的定义方式,可以保持对 <2.2.3 版本基础库的兼容
  attached() {
    // 在组件实例进入页面节点树时执行
  },
  detached() {
    // 在组件实例被从页面节点树移除时执行
  },
  // ...
})

tina 的 component 支持旧的,不支持新的

callmesoul avatar Apr 28 '19 07:04 callmesoul