English
renderjs
is a js that runs in the view layer. It is more powerful than WXS. It only supports app-vue and web.
renderjs
has two main functions:
Platform difference description
App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序、飞书小程序 | QQ小程序 |
---|---|---|---|---|---|---|
√(2.5.5+, vue only) | √ | x | x | x | x | x |
Set lang of script node to renderjs
<script module="test" lang="renderjs">
export default {
mounted() {
// ...
},
methods: {
// ...
}
}
</script>
echarts
on app and h5 through renderjsThe app-side logic layer of uni-app is separated from the view layer. This mechanism has many benefits, but it also has a side effect of blocking communication between the two layers. In particular, the blocking problem on the Android side of the App affects the production of high-performance applications.
renderjs
runs on the view layer and can be used to directly manipulate the elements of the view layer to avoid communication loss.
In the canvas example of hello uni-app, renderjs
is used on the App side, and the renderjs
running in the view layer directly operates the canvas of the view layer, realizing a smooth canvas animation example far exceeding the WeChat applet. Specifically, experience it in the example of hello uni-app, and compare the performance difference between the App side and the applet side.
The official does not recommend operating dom in uni-app, but if you do not develop small programs and want to use some libraries that operate dom and window, you can actually use renderjs
to solve it.
In the app-vue environment, the view layer is rendered by the webview, and renderjs
runs on the view layer, which can naturally operate dom and window.
This is an example of running the full version of echart based on renderjs
: renderjs version of echart
In the same way, libraries such as f2
and threejs
can all be used in this way.
setup script
用法。