当前位置: 首页 > news >正文

uniapp renderjs 逻辑层,视图层互相传递数据封装

uniapp renderjs 逻辑层,视图层互相传递数据封装

<template><view class="content"><view :prop="sender" :change:prop="renderMaps.handleAction"><button @click="renderMaps.viewInit">向逻辑层发送数据</button><button @click="luoInif">向视图层发送数据</button><button @click="luojiFn">触发逻辑层的方法</button></view></view>
</template>
<!-- 逻辑层 -->
<script>
export default {data() {return {sender: {handle: "", //调用视图层方法的名字callback: "", //回调函数的名字options: null, //传递给视图层的数据rendCallback: "", //视图层的回调函数的名字(可选)暂时无用},}},created() {console.log(1)// 逻辑层向视图层传递数据this.sendMsg("init", "handleFeaturePopup", { id: 10 }, (e) => {console.log("视图层回调函数执行了,可以在这里做一些逻辑处理", e)})},mounted() {console.log(2)},methods: {/*** 视图层触发逻辑层方法 类似子传父* @param event callback 逻辑层的方法名称* @param event param 传递给逻辑层的数据*/handleItemClick(event) {const handle = this[event.callback]handle && handle(event.param)},/*** 逻辑层传递数据到视图层 类似父传子** @param handle 触发视图层的方法名称* @param callback 逻辑层的方法名称* @param options 消息发送的配置选项* @param rendCallback 逻辑层的回调函数(可选)暂时无用*/sendMsg(handle, callback, options, rendCallback) {this.sender = {handle,callback,options,rendCallback,}},handleFeaturePopup(options) {console.log("options:", options)console.log("逻辑层接受到了数据:", options)},luoInif() {this.sendMsg("init", "handleFeaturePopup", { id: 100 }, (e) => {console.log("视图层回调函数执行了,可以在这里做一些逻辑处理", e)})},},
}
</script>
<!-- 视图层 -->
<!-- <script> -->
<script module="renderMaps" lang="renderjs">
let map = null
export default {data() {return {//逻辑层的方法名称callback: "",}},mounted() {console.log(3)},created() {console.log(4)},methods: {//监听逻辑层传递过来的数据handleAction(newValue, oldValue, ownerInstance, instance) {console.log("逻辑层传递过来的数据", newValue)const handle = this[newValue.handle]let options = newValue.options//保存逻辑层的方法名称this.callback = newValue.callbackif (!options) {options = undefined}if (!handle) {console.info("参数为标记需要执行的方法")return}handle(options, newValue?.rendCallback)},init(options, fn) {console.log("视图层接受到数据了")// 回调fn("11")},viewInit() {console.log("视图层向逻辑层发送数据-------------------------------------------")this.$ownerInstance.callMethod("handleItemClick", {callback: "handleFeaturePopup",param: {name: "李四",age:11,},})},luojiFn(){console.log("this.callback:",this.callback);this.$ownerInstance.callMethod("handleItemClick", {callback: this.callback,param: {name: "李四11",age:11,},})}},
}
</script>
<style lang="scss" scoped></style>
http://www.lryc.cn/news/611280.html

相关文章:

  • 背包初步练习
  • 计算机视觉面试保温:CLIP(对比语言-图像预训练)和BERT技术概述
  • Linux逻辑卷管理操作指南
  • 论文解读:Mamba: Linear-Time Sequence Modeling with Selective State Spaces
  • JSP相关Bug解决
  • AutoSar AP LT规范中 建模消息和非建模消息都可以使用LogInfo() API吗?
  • 达芬奇31-40
  • stm32F407 硬件COM事件触发六步换相
  • AI赋能复合材料与智能增材制造:前沿技术研修重磅
  • 智能融合:增材制造多物理场AI建模与工业应用实战
  • 【面向对象】面向对象七大原则
  • linux nfs+autofs
  • 注意点:Git 从安装到分支协作、冲突解决的完整步骤 ---待修改,没看这个步骤,需要重新整理步骤
  • ara::log::LogStream::WithTag的概念和使用案例
  • 跨域场景下的Iframe事件监听
  • Nature Neuroscience | 如何在大规模自动化MRI分析中规避伪影陷阱?
  • Android 开发中,HandlerThread、IntentService 和 AsyncTask区别对比
  • 性能测试终极指南:从指标到实战
  • 《传统企业如何借助数字化转型实现企业增长》
  • 机器学习通关秘籍|Day 03:决策树、随机森林与线性回归
  • 分布式微服务--Nacos持久化
  • Python-机器学习初识
  • 机器学习——集成学习(Ensemble Learning):随机森林(Random Forest),AdaBoost、Gradient Boosting,Stacking
  • 论文阅读笔记:《Curriculum Coarse-to-Fine Selection for High-IPC Dataset Distillation》
  • 2.4 组件通信
  • 高阶 RAG :技术体系串联与实际落地指南​
  • 计算机网络 第2章通信基础(竟成)
  • PYQT的QMessageBox使用示例
  • 深入理解 Ext 系列文件系统:从磁盘物理到文件系统原理
  • 注意点:如何使用conda创建虚拟环境并使用虚拟环境以及当安装相关库时,如何指定安装到那个环境里面 ---待看