this.$ownerInstance.callMethod('onRenderjsMessage', {
a: 1
})
上面可以把数据从视图层发到服务层,服务层要如何主动发数据给视图层?
this.$ownerInstance.callMethod('onRenderjsMessage', {
a: 1
})
上面可以把数据从视图层发到服务层,服务层要如何主动发数据给视图层?
4***@qq.com (作者)
官方不靠谱,还得靠自己
定义一个services2render.vue组件用做中转
<template>
<view class="services2render" @postMessage="postMessage"></view>
</template>
<script>
export default {
data() {
return {}
},
methods:{
postMessage(data){
this.$emit('postMessage',data)
}
}
}
</script>
<style lang="scss" scoped>
.services2render{
display: none;
}
</style>
<template>
<view class="home">
<services2render ref="services2render" @postMessage="scrollRender.postMessage"></services2render>
</view>
</template>
<script>
import services2render from "@/pages/components/services2render.vue";
export default {
components: {
services2render
},
methods: {
postMessage(){
// 调用这个方法主动给renderjs发数据
let data = {}
this.$refs.services2render.postMessage(data)
}
}
}
</script>
<script module="scrollRender" lang="renderjs">
export default {
methods: {
postMessage(data) {
console.log('postMessage', data)
}
}
}
</script>
4***@qq.com (作者)
方法无效
2020-12-05 11:20