当前位置:网站首页>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>
边栏推荐
猜你喜欢
nodejs 时钟案例(fs模块),重复使用fs.writeFile方法,旧内容会被覆盖
推荐几款好用的MySQL开源客户端,建议收藏
从零开始配置 vim(9)——初始配置
flex 的 三个参数:flex-grow、flex-shrink、flex-basis
如何让导电滑环信号更好
一个刚入行的测试员怎么样做好功能测试?测试思维真的很重要
同样是初级测试,凭什么他比我薪资高 5000 块?
带你深入理解3.4.2的版本更新,对用户带来了什么?
MySQL: Introduction to Logging System | Error Log | Query Log | Binary Log: Bin-log Data Recovery Practice | Slow Log Query
Example 045: Summation
随机推荐
what is a microcontroller or mcu
mock模拟,skip,skipif,mark分类
小程序分包及分包预下载
单体架构应用和分布式架构应用的区别
兴业数金一面
使用flink-sql写入mysql的时候,只指定插入的字段,但是会报错id字段错误,没有默认值,创
2022.8.8 Exam written in memory (memory)
matlab simulink响应谱计算
What is a Cross-Site Request Forgery (CSRF) attack?How to defend?
[Red Team] ATT&CK - Self-starting - Self-starting mechanism using LSA authentication package
What makes training multi-modal classification networks hard?
How to write a high-quality test case?
成功执行数字化转型的9个因素
Chip Accelerator
nodejs 时钟案例(fs模块),重复使用fs.writeFile方法,旧内容会被覆盖
Example 048: Number ratio size
Research on IC enterprises
盘式导电滑环的优点和缺点
The 25th day of the special assault version of the sword offer
有关视频传输时粘包问题的一些解决方法