wepy2.0中组件没有pageLifetimes生命周期吗

rjjhvcjd  于 2022-10-20  发布在  其他
关注(0)|答案(5)|浏览(263)

Description

wepy2.0中组件没有pageLifetimes生命周期吗
想在页面显示时都检测是否要显示这个组件

1mrurvl1

1mrurvl11#

有,例子如下:

<script>
import wepy from '@wepy/core';

wepy.component({
  data: {
    StatusBar: 0,
    CustomBar: 0,
    Custom: 0
  },
  created: function() {
    console.log(123456);
  },
  attached: function() {
    console.log(123);
    // 在组件示例进入页面节点树时执行
  },
  props: {
    bgColor: {
      type: String,
      default: ''
    },
    isCustom: {
      type: [Boolean, String],
      default: false
    },
    isBack: {
      type: [Boolean, String],
      default: false
    },
    bgImage: {
      type: String,
      default: ''
    },
    test: {
      type: Number,
      default: 0
    }
  },

  methods: {
    BackPage() {
      wx.navigateBack({
        delta: 1
      });
    },
    toHome() {
      wx.reLaunch({
        url: '/pages/index/index'
      });
    }
  }
});
</script>
zdwk9cvp

zdwk9cvp4#

上面写了,这个就是生命周期
created: function() {
console.log(123456);
},
attached: function() {
console.log(123);
// 在组件示例进入页面节点树时执行
},

svmlkihl

svmlkihl5#

上面写了,这个就是生命周期
created: function() {
console.log(123456);
},
attached: function() {
console.log(123);
// 在组件示例进入页面节点树时执行
},

例如组件需要捕获 页面的onshow事件怎么做?
我只能是 用原生组件捕获了,然后在wepy组件中使用原生组件emit的事件来处理响应

相关问题