当前位置:网站首页>小程序: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倍),安卓设备(两者无差异)
边栏推荐
- error: redefinition of ‘xxx‘
- Fluke dtx-sfm2 single mode module of a company in Hangzhou - repair case
- USB network native driver for esxi updated to support esxi7.0.1
- 使用wampserver3.2.6时切换中文时造成启动失败
- Filter
- MySQL delete tables without deleting databases
- 微信小程序自定义编译模式
- My notes
- Trouble encountered in cable testing -- a case study of a manufacturer?
- 【学习笔记】进程创建
猜你喜欢
![[server usage record] log in to the remote server through the springboard machine and transfer files](/img/11/1ca6c2f34d43dfb6d766ec0dc3371d.png)
[server usage record] log in to the remote server through the springboard machine and transfer files

OpenGL的开发环境配置【VS2017】+常见问题

How to test industrial Ethernet cables (using fluke dsx-8000)?

Pycharm2019设置编辑器主题和默认代码

VAN(DWConv+DWDilationConv+PWConv)

set_ false_ path

Word邮件合并功能详解:合并后生成多个word文档,删除空白页

Matlab simulation of radar imaging 2 - pulse compression and windowing

Word自动目录字体修改和行间距的问题

mysql join技巧
随机推荐
详解安装msdn 2015及其注意事项
JSON笔记
【学习笔记】知识管理
What happens when MySQL tables change from compressed tables to ordinary tables
Bert bidirectional encoder based on transformer
qt批量操作控件,并设置信号槽
雷达成像 Matlab 仿真 4 —— 距离分辨率分析
Talk about the "hybrid mode" of esxi virtual switch and port group
QT parse string into JSON data and parse
How can fluke dsx2-5000 and dsx2-8000 modules find the calibration expiration date?
听说你也在实习|当我采访了几个大三实习生之后。
ubuntu mysql 设置远程访问权限
What are the common English questions in the postgraduate interview?
EMC experiment practical case ESD electrostatic experiment
Hugging face 的问题记录 I
MySQL delete tables without deleting databases
Bag of tricks training convolution network skills
Matlab simulation of radar imaging 4 - range resolution analysis
MySQL join skills
qt中获取当前目录