herenowts
herenowts
  • 发布:2023-05-16 15:20
  • 更新:2024-07-09 11:36
  • 阅读:466

renderjs 使用记录

分类:uni-app

<template>  
    <view>  
        <view @tap="MyRenderjsModule.eventChange" style="width: 300rpx;height: 120rpx;background-color: rgb(0, 255, 0);display: flex;justify-content: center;align-content: center;align-items: center;">Click Me, Please</view>  

        <view :prop="mainTag" :change:prop="MyRenderjsModule.mainTagUpdate"></view>  
    </view>  
</template>  

<script module="MyRenderjsModule" lang="renderjs">  
    export default {  
        data() {  
            return {  
                renderTag: ''  
            }  
        },  
        mounted() {  

        },  
        methods: {  
            mainTagUpdate(newVal, oldVal, ownerInstance, instance) {  
                console.log(`renderTag will update form ${oldVal} to ${newVal} by prop mainTag`)  
                this.renderTag = newVal  

                let mainTag = ''  
                // #ifdef APP-PLUS  
                mainTag = plus.storage.getItem('mainTag')  
                // #endif  
                // #ifndef APP-PLUS  
                mainTag = uni.getStorageSync('mainTag')  
                // #endif  

                console.log(`mainTagUpdate call cache mainTag = ${mainTag}`)  
            },  
            eventChange(event, ownerInstance) {  
                console.log(`Event "eventChange" triggered`)  

                ownerInstance?.callMethod('mainCallBack', {param: 'abc'})  
            },  
        },  
    }  
</script>  

<script>  
    export default {  
        data() {  
            return {  
                mainTag: ''  
            }  
        },  
        onLoad(options) {  

            setInterval(()=>{  
                this.mainTag = (new Date()).toString()  

                // #ifdef APP-PLUS  
                plus.storage.setItem('mainTag', this.mainTag)  
                // #endif  
                // #ifndef APP-PLUS  
                uni.setStorageSync('mainTag', this.mainTag)  
                // #endif  

            }, 3000)  
        },  
        methods: {  
            mainCallBack(obj = {}){  
                console.log(`Event "mainCallBack" triggered by renderjs call "mainCallBack"`)  
            }  
        }  
    }  
</script>  

<style>  

</style>  
0 关注 分享

要回复文章请先登录注册

超级无敌APP

超级无敌APP

回复 aak12345 :
renderjs里无法使用uni.$on啊。大佬。。是不是说错啦?我这写这个报错。。提示找不到uni.$on is not a function
2024-07-09 11:36
aak12345

aak12345

https://uniapp.dcloud.net.cn/api/window/communication.html uni主动发消息给iframe,可以在renderjs里面添加uni.$on,然后在uni里面uni.$emit
2023-11-08 19:20