4***@qq.com
4***@qq.com
  • 发布:2020-11-27 11:08
  • 更新:2020-12-04 18:03
  • 阅读:1124

renderjs如何主动发数据给视图层

分类:uni-app
this.$ownerInstance.callMethod('onRenderjsMessage', {  
    a: 1  
})

上面可以把数据从视图层发到服务层,服务层要如何主动发数据给视图层?

2020-11-27 11:08 负责人:无 分享
已邀请:
4***@qq.com

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>  

该问题目前已经被锁定, 无法添加新回复