当前位置:网站首页>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>
边栏推荐
猜你喜欢
随机推荐
The Evolutionary History of the "Double Gun" Trojan Horse Virus
2022.8.9 Exam Unique Bid Auction--800 Question Solutions
flutter 创建可增型列表和列表排序
2022/08/09 学习笔记 (day26) IO流
plsql 查询数据库操作历史记录(Ctrl + e)
[8.8] Code Source - [Non-falling subarray game] [Longest rising subsequence count (Bonus)] [Substring (data enhanced version)]
yolov5+usb相机
实例043:作用域、类的方法与变量
2022.8.8 Exam written in memory (memory)
三极管开关电路参数设计与参数介绍
MongoDB 常用查询语句
黑马jvm课程笔记d2
小程序分包及分包预下载
excel高级绘图技巧100讲(二十三)-Excel中实现倒计时计数
Chip Accelerator
Excel Advanced Drawing Skills 100 Lectures (23) - Countdown Counting in Excel
Example 043: Scope, class methods and variables
驱动程序开发:无设备树和有设备树的platform驱动
如何快速成为一名软件测试工程师?测试员月薪15k需要什么技术?
Camera partial update









