小程序P51 13.wxs的基本用法
1、定义内嵌的wxs脚本
<!--pages/massage/massage.wxml-->
<view>{{m1.toUpper(username)}}</view>
<wxs module="m1">
module.exports.toUpper = function(str){
return str.toUpperCase()
}
</wxs>
// pages/massage/massage.js
data: {
count:0,
username:'zhangshan',
country:'CHAN'
},
2、定义外联的wxs脚本
//在utils文件下创建tools.wxs文件
function toLower(str){
return str.toLowerCase()
}
module.exports = {
toLower:toLower
}
3、使用外联wxs脚本
<!--pages/massage/massage.wxml-->
<view>{{m2.toLower(country)}}</view>
<wxs src="../../utils/tools.wxs" module="m2"></wxs>