-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Taro转微信小程序,无法调用微信小程序自动化测试api page.callMethod #4439
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
虽然我目前没完全确认,但我已知的是Taro的抖音小程序的Page对应Page,Taro的微信小程序是Page对应Component isPage上。所以我是给Page上加了装饰类(高阶函数) |
Hello~ 您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。 如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。 Good luck and happy coding~ |
不是很理解,方便贴下代码吗? |
在dist/pages/index里面的最后一行代码示意: // 微信小程序
Component(require('../../npm/@tarojs/taro-weapp/index.js').default.createComponent(Index, true));
});
// 抖音小程序
Page(require('../../npm/@tarojs/taro-tt/index.js').default.createComponent(Index, true)); 而在taro-weapp源码中有一些判断代码,我觉得帮助你理解 // packages/taro-weapp/src/create-component.js
if (isPage) {
weappComponentConf.methods = weappComponentConf.methods || {}
weappComponentConf.methods['onLoad'] = function (options = {}) {
if (this.$component.__isReady) return
Object.assign(this.$component.$router.params, options)
initComponent.apply(this, [ComponentClass, isPage])
}
weappComponentConf.methods['onReady'] = function () {
this.$component.__mounted = true
componentTrigger(this.$component, 'componentDidMount')
}
weappComponentConf.methods['onShow'] = function () {
componentTrigger(this.$component, 'componentDidShow')
}
weappComponentConf.methods['onHide'] = function () {
componentTrigger(this.$component, 'componentDidHide')
}
pageExtraFns.forEach(fn => {
if (componentInstance[fn] && typeof componentInstance[fn] === 'function') {
weappComponentConf.methods[fn] = function () {
const component = this.$component
if (component[fn] && typeof component[fn] === 'function') {
// eslint-disable-next-line no-useless-call
return component[fn].call(component, ...arguments)
}
}
}
})
__wxRoute && cacheDataSet(__wxRoute, ComponentClass)
} else {
weappComponentConf.pageLifetimes = weappComponentConf.pageLifetimes || {}
weappComponentConf.pageLifetimes['show'] = function () {
componentTrigger(this.$component, 'componentDidShow')
}
weappComponentConf.pageLifetimes['hide'] = function () {
componentTrigger(this.$component, 'componentDidHide')
}
weappComponentConf.pageLifetimes['resize'] = function () {
componentTrigger(this.$component, 'onResize')
}
} |
感谢,这也是一种思路。 |
@iSung // page.js
import Taro from '@tarojs/taro'
/**
* 为 page 级别组件添加公共方法,向被装饰组件塞入 props
* @param {ReactComponentLike} TaroComponent
*/
export default function WithPage(TaroComponent) {
class CorePage extends TaroComponent {
static options = {
addGlobalClass: true
}
componentDidShow() {
wx.bisdk && wx.bisdk.onPageShow && wx.bisdk.onPageShow()
if (super.componentDidShow) {
super.componentDidShow()
}
}
}
CorePage.displayName = TaroComponent.displayName
|| TaroComponent.name
|| 'CorePage'
return CorePage
} // pages/index/index.js
import CorePage from '../../page'
@CorePage
export default class Index extends Component {
render(){
}
} |
问题描述
Taro转微信小程序,无法调用微信小程序自动化测试api page.callMethod,但原生微信小程序可以调用。
复现步骤
系统信息
补充信息
初步排查可能跟Taro转微信小程序component方法挂载有关系,Taro小程序component绑定方法全部挂载在page__proto__上,未绑定方法未挂载。原生小程序则是全部挂载在page上,具体参照以下截图。
The text was updated successfully, but these errors were encountered: