当前位置:网站首页>小程序:wsx脚本
小程序:wsx脚本
2022-07-28 05:25:00 【像费曼%】
1.wxs的应用场景
wxml无法调用.js的函数,但可以调用wxs中定义的函数。因此小程序中wxs的典型应用场景是“过滤器”
2.wxs与JavaScript的关系
3.wxs基础语法
3.1内联:wxs代码可以编写在wxml文件中的<wxs>标签内
wxml文件中的<wxs></wxs>标签,必须提供module属性,用来指定当前wxs模块的名称,方便在wxml中访问模块中的成员
//在data中设置username属性
<view>{
{m1.toUpper(username)}}</view>
<wxs module="m1">
module.exports.toUpper = function(str){
return str.toUpperCase()
}
</wxs>3.2外联
与pages文件夹同级下的utils创建tools.wxs文件
<view>{
{m2.toLower(country)}}</view>
<wxs src="../../utils/tools.wxs" module="m2"></wxs>
//tools.wxs
function toLower(str){
return str.toLowerCase()
}
module.exports = {
toLower:toLower
}4.wxs特点
- 在wxs中定义的函数,不能作为组件的事件回调函数
//错误示范
<button bindtap='m2.toLower'>按钮</button>- 隔离性(运行环境与JavaScript隔离) wxs不能调用js定义的函数、也不能调用小程序提供的API
- 性能好:ios设备(wxs快于JavaScript2-20倍),安卓设备(两者无差异)
边栏推荐
- ICC2使用report_placement检查floorplan
- VAN(DWConv+DWDilationConv+PWConv)
- [yolov5] environment construction: win11 + mx450
- Design and analysis of contactor coil control circuit
- What about the insufficient memory of Clickhouse aggregation? Then improve the polymerization performance
- Low power design isolation cell
- Matlab simulation of radar imaging 2 - pulse compression and windowing
- My notes
- Paper artifact vs code + latex + latex workshop
- Talk about the "hybrid mode" of esxi virtual switch and port group
猜你喜欢

How many columns are the most suitable for Clickhouse to build a width table?

【服务器使用记录】通过跳板机登录远程服务器并进行文件传输

量化交易机器人系统开发

ICC2(一)Preparing the Design

qt实现将相关信息输出到日志文件

天线效应解决办法

I heard that you are also practicing when I interviewed several junior interns.

Matlab simulation of radar imaging 1 - LFM signal and its spectrum

雷达成像 Matlab 仿真 1 —— LFM信号及其频谱

Vscode中,无法打开源文件 “Adafruit_GFX.h“
随机推荐
qt中Qthread线程的使用以及安全关闭
Monitor the CPU temperature of raspberry pie 4B installed with esxi on ARM
Pytorch learning note 4 - automatic calculation of gradient descent autograd
Weight decay
机器学习笔记 5 —— Logistic Regression
EfficientNET_ V1
qt绘画事件-设置背景图片
Perl Introduction (10) formatted output
根据IP地址和子网掩码求主机所在的网络地址和广播地址
Beginners choose sensors
Talking about fluke optical cable certification? What is CFP? What is OFP?
ClickHouse 中的公共表表达式CTE
What happens when MySQL tables change from compressed tables to ordinary tables
Low power design isolation cell
How to use the bit error meter?
Pytorch learning notes 1 - quick start
clickhouse建宽表多少列最合适?
mysql删表不删库
Machine learning note 5 - logistic regression
解决内存占用比应用进程占用高的问题