子组件监听父组件传递信息 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) } }) } } })