组件内部通过 behaviors 的方式对外抛出实例时,父组件使用selectComponent子组件的实例为null
Component({
behaviors: ['wx://component-export'],
export() {
return { myField: 'myValue' }
}
})
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 12.6.6
第三方开发者工具版本号: 1.06.2303220
基础库版本号: 2.30.0
项目创建方式: CLI
CLI版本号: 5.0.8
组件内部通过 behaviors 的方式对外抛出实例时,父组件使用selectComponent子组件的实例为null
Component({
behaviors: ['wx://component-export'],
export() {
return { myField: 'myValue' }
}
})
父组件使用selectComponent获取子组件的实例,返回不为null
父组件使用selectComponent子组件的实例为null
源码路径:packages/uni-mp-weixin/dist/index.js
对应function:parseBaseComponent
这个方法中,对传入的vueComponentOptions参数进行了过滤,若自定义组件通过 export 抛出了对应的实例,这时候会被过滤掉。导致微信小程序通过selectComponent方法获取组件实例时,会返回null。
期望 parseBaseComponent 能增加 export 参数的返回
微信小程序官方文档:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E7%BB%84%E4%BB%B6%E5%AE%9E%E4%BE%8B%E8%8E%B7%E5%8F%96%E7%BB%93%E6%9E%9C
0 个回复