wxs特点:
js的data中
data: {
username:'lhm',//测试内嵌wxs数据
country:'CHINA', //使用外联wxs数据
count:0
},
1.内嵌式
<text>通过内嵌的方式使用wxs的方法</text>
<view>{{m1.toUpper(username)}}</view>
<wxs module="m1">
module.exports.toUpper=function(str){
return str.toUpperCase();
}
</wxs>
2.外联式 在utils中新建了info.wxs文件
function toLower(str){
return str.toLowerCase();
}
module.exports={
toLower:toLower
}
使用 src说明路径,必须是相对路径
<text>通过外联的方式使用wxs的方法</text>
<view>{{m2.toLower(country)}}</view>
<wxs src="../../utils/info.wxs" module="m2" ></wxs>
效果图: