You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<template><wxssrc="../wxs/components/list.wxs"module="list"><view>{{list.FOO}}</view></template>
// wxs/components/list.wxs
const Foo = 'This is from list wxs module'
module.exports = {Foo}
Wxs 是小程序自己推出的一套脚本语言。官方文档给出的示例,wxs 模块必须要声明式的被 wxml 引用。和 js 在 jsCore 当中去运行不同的是 wxs 是在渲染线程当中去运行的。因此 wxs 的执行便少了一次从 jsCore 执行的线程和渲染线程的通讯,从这个角度来说是对代码执行效率和性能上的比较大的一个优化手段。
有关官方提到的有关 wxs 的运行效率的问题还有待论证:
因为 mpx 是对小程序做渐进增强,因此 wxs 的使用方式和原生的小程序保持一致。在你的
.mpx
文件当中的 template block 内通过路径直接去引入 wxs 模块即可使用:在 template 模块经过 template-compiler 处理的过程中。模板编译器 compiler 在解析模板的 AST 过程中会针对 wxs 标签缓存一份 wxs 模块的映射表:
当 compiler 对 template 模板解析完后,template-compiler 接下来就开始处理 wxs 模块相关的内容:
The text was updated successfully, but these errors were encountered: