当前位置:网站首页>renderjs usage in uni-app
renderjs usage in uni-app
2022-07-31 19:31:00 【studyXia Yu】
对于UNI APP端的开发而言,Because there is nodocument,cannot be correlatedDOM操作,同时有关DOMRendering third-party library(echart、openlayer等)also cannot be used effectively,Hence the official launchrenderjs方案,来解决上述问题.
renderjs是一个运行在视图层的js
renderjs的主要作用有2个:
大幅降低逻辑层和视图层的通讯损耗,提供高性能视图交互能力
在视图层操作dom,运行for web的js库
renderjs和service层的通信
具体分为三部分:
1.在templateevents are triggered by manual user actions
2.在service层中调用方法
3.在renderjs中调用方法
从renderjs到service层:通过this.$ownerInstance.callMethod()方法可以调用service中的方法,第一个参数是方法名,The second parameter is the parameter passed in the past
使用方式
设置 script 节点的 lang 为 renderjs
script的module的名称可以随便取,module=(值任意,相当于命名空间,The method in it will then be called according to this name),但是change:参数名称必须和module保持一致,Although not blockedrenderjs的运行,但是会报错,It can also cause changes in data not to be captured
<script module="test" lang="renderjs">
export default {
mounted() {
// ...
},
methods: {
// ...
}
}
</script>
<template>
<view>
<!-- prop是个名字,可以随意改,注意:change:[name]The two names need to be the same -->
<!-- 从service层到renderjs:首先在template中绑定一个service中定义的值,Then add at the same location:change:(属性名)=(renderjs的module名.触发的方法)来实现通信.
简单来说就是serviceResponsible for data changes,通过templateMonitor data changes to notifyrenderjs
this.$ownerInstance.callMethodThe method must be executed through the click event-->
<!-- msg是要向renderjs发送的数据,testRenderjs 为renderjs模块名称,onChange是renderjs中的监听方法 -->
<view :prop="msg" :change:prop="testRenderjs.onChange" id="renderjs-view">{
{
msg}}</view>
<button @tap="changeMsgFn">点击修改options</button>
<button @tap="testRenderjs.emitData">直接调用renderjs中的emitData方法</button>
</view>
</template>
<script>
// 原先的script,这里被称为service层
export default {
data() {
return {
// Stored here ready to pass torenderjs的数据
msg: "我是servicelayer originalmsg"
}
},
methods: {
// 触发service层 出入renderjs数据改变
changeMsgFn() {
// 修改msg 触发change
this.msg = "msg的值变了"
},
// 接收renderjs发回的数据
acceptDataFromRenderjs(data) {
console.log('从renderjs中接收到的数据', data)
this.msg = data.content
}
}
}
</script>
<!-- testRenderjs 为renderjs模块名称,lang固定写法 -->
<script module="testRenderjs" lang="renderjs">
export default {
data() {
return {
content:"我是来自renderjs的数据"
}
},
created() {
console.log('renderjs初始化完毕')
},
mounted() {
const view = document.getElementById('renderjs-view')
const button = document.createElement('button')
button.innerText = '一个按钮'
view.appendChild(button)
},
methods: {
// Receive logic layerservicedata sent by the layer
onChange(newValue, oldValue, ownerInstance, instance) {
console.log('service层中的options发生变化')
console.log('新值newValue', newValue)
console.log('旧值oldValue', oldValue)
// ownerInstance和this.$ownerInstance一样,可用来向service层通信
// instance和ownerInstance的区别是:
// instance.$elPoints to the node that triggered the event;ownerInstance.$el指向当前vue文件中的根节点;
// instancerole is not yet clear,The official usage is not given
},
// 发送数据到service层
emitData(event, ownerInstance) {
// event是事件对象
ownerInstance.callMethod('acceptDataFromRenderjs', {
content: this.content
})
// 或者
/* this.$ownerInstance.callMethod('acceptDataFromRenderjs',{
content:this.content
}) */
// 需要注意的是:Only throughtemplateTriggered by user manual operationrenderjsThe method parameters are these two:event, ownerInstance;Function parameters triggered by other methods are not the same
}
}
}
</script>
边栏推荐
- ThreadLocal
- 【AcWing】第 62 场周赛 【2022.07.30】
- INeuOS industrial Internet operating system, the equipment operational business and "low code" form development tools
- 淘宝/天猫获得淘口令真实url API
- Unity 之 音频类型和编码格式介绍
- Architect 04 - Application Service Encryption Design and Practice
- C# 之 扑克游戏 -- 21点规则介绍和代码实现
- leetcode:6135. 图中的最长环【内向基环树 + 最长环板子 + 时间戳】
- 【码蹄集新手村600题】不通过字符数组来合并俩个数字
- 性能优化:记一次树的搜索接口优化思路
猜你喜欢
MySQL - single function
35道MySQL面试必问题图解,这样也太好理解了吧
How programmers learn open source projects, this article tells you
Apache EventMesh distributed event-driven multi-runtime
Redis Overview: Talk to the interviewer all night long about Redis caching, persistence, elimination mechanism, sentinel, and the underlying principles of clusters!...
35 MySQL interview questions and diagrams, this is also easy to understand
Introduction to Audio Types and Encoding Formats in Unity
Basic configuration of OSPFv3
SiC MOSFET的短路特性及保护
AI 自动写代码插件 Copilot(副驾驶员)
随机推荐
JD.com searches for products by keyword API
leetcode:6135. 图中的最长环【内向基环树 + 最长环板子 + 时间戳】
c语言解析json字符串(json对象转化为字符串)
cas与自旋锁(轻量级锁就是自旋锁吗)
The new telecom "routine", my dad was tricked!
idea中搜索具体的字符内容的快捷方式
Kotlin coroutines: continuation, continuation interceptor, scheduler
【AcWing】The 62nd Weekly Match 【2022.07.30】
Basic Grammar Introduction of Carbon Tutorial (Tutorial)
Basics of ResNet: Principles of Residual Blocks
How can we improve the real yourself, become an excellent architect?
1161. Maximum Sum of Elements in Layer: Hierarchical Traversal Application Problems
uni-app中的renderjs使用
AI 自动写代码插件 Copilot(副驾驶员)
淘宝/天猫获得淘口令真实url API
京东获取商品历史价格信息 API
&lt;artifactId&gt;ojdbc8&lt;/artifactId&gt;「建议收藏」
第七章
pytorch lstm时间序列预测问题踩坑「建议收藏」
求n以内的素数