当前位置:网站首页>applet wxs
applet wxs
2022-08-10 03:59:00 【listen to me】
What is wxs
wxs (weixin script) is a set of scripting languages unique to the applet. Combined with wxml, the structure of the page can be constructed
Application scenarios of wxs
The function defined in the .js of the page cannot be called in wxml, however, the function in wxs can be called in wxml.Therefore, the typical application scenario of wxs in applet is "filter"
The relationship between wxs and JavaScript
- wxs has its own data type
- number, string, Boolean, Object, function, array, date, regexp
- wxs does not support syntax similar to ES6 and above
- Not supported: let, const, destructuring assignment, spread operator, arrow function, object property shorthand, etc.
- Support: var definition variable, common function function
- wxs follows CommonJS specification
- module object
- require() function
- module.exports object
Basic usage of wxs
1. Define an inline wxs script
wxs code can be written in tags in wxml files, just like JavaScript code can be written in html files
2. Define the wxs script for outreach
wxs code can also be written in files with a .wxs extension, just as JavaScript code can be written in files with a .js extension.Sample code:
// tools.wxs filefunction toLower(str){return str.toLowerCase();}module.exports = {toLower:toLower}Use of outbound scripts
When introducing an external wxs script in wxml, you must add module and src attributes to the tag, where:
- module is used to specify the name of the module
- src is used to specify the path of the script to be imported, and must be a relative path
Sample code:
view>{{m2.toLower(country)}}</view><wxs src="../../utils/tools.wxs" module="m2"></wxs>
边栏推荐
猜你喜欢
随机推荐
使用flink-sql写入mysql的时候,只指定插入的字段,但是会报错id字段错误,没有默认值,创
想要避免After Effects渲染失败的问题,5个小技巧必看
Example 043: Scope, class methods and variables
MySQL: Introduction to Logging System | Error Log | Query Log | Binary Log: Bin-log Data Recovery Practice | Slow Log Query
IDEA自动生成serialVersionUID
Example 047: Functions Swap Variables
【Image Classification】2022-CycleMLP ICLR
二进制与内存
实例048:数字比大小
“双枪”木马病毒的进化史
如何使用腾讯字体,已经在什么场合下可以使用该字体?TTTGB-Medium
Example 048: Number ratio size
使用curl指令发起websocket请求
[Kali Security Penetration Testing Practice Course] Chapter 7 Privilege Escalation
所谓软件测试工作能力强,其实就是这 5 点
【图像分类】2022-ConvMixer ICLR
Pycharm中6个常用插件推荐
Day16 charles的基本使用
如何编写一份优质的测试用例?
matlab simulink响应谱计算









