子组件监听父组件传递信息 observers

observers: {
    'show': function (val) {
      const that = this;
      that.setData({
        showTitlt: val
      }, () => {
        if(val){
          setTimeout(() => {
            that.triggerEvent('myevent', false)
          }, 2000)
        }
      })
    }
  }

全JS

// components/warn/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      default: false,
      value: '登录失败'
    },
    show: {
      type: Boolean,
      default: false
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    showTitlt:false 
  },

  /**
   * 组件的方法列表
   */
  methods: {

  },
  observers: {
    'show': function (val) {
      const that = this;
      that.setData({
        showTitlt: val
      }, () => {
        if(val){
          setTimeout(() => {
            that.triggerEvent('myevent', false)
          }, 2000)
        }
      })
    }
  }
})
View Code

 

posted @ 2021-09-07 15:58  还有什么值得拥有  阅读(83)  评论(0编辑  收藏  举报