小程中使用bus实现兄弟组件传参
-
1、安装iny-bus
npm i iny-bus -
2、使用index.js
// 自定义组件页面 import bus from 'iny-bus' Component({ lifetimes: { created() { // 接收 bus.on('changetab', (res) => { this.getlist() }) }, detached() { // 销毁 bus.remove('changetab') } }, }) // 正常页面 import bus from 'iny-bus' Page({ onLoad: function (options) { // 接收 bus.on('changetab', (res) => { this.getlist() }) }, tabbtn() { // 传送 bus.emit('clickme', true) } })