#### WXS(WeiXin Script)是小程序的一套腳本語言,結合`WXML`,可以構建出頁面的結構。
wxml中的數據,需要過濾的話,無法像vue中那樣,直接添加一個函數去使用,在微信小程序中通常用wxs來過濾。
具體使用方法(不支持es6語法):
1.新建一個wxs文件,推薦建在utils中

```
案例:過濾字符串,添加對應單位
function fornatCount(count){
var countVal = parseInt(count);
if(countVal > 100000000){
return (countVal / 100000000).toFixed(1) + "億"
}else if(countVal > 10000){
return (countVal / 10000).toFixed(1) + "萬"
}else{
return countVal + ""
}
}
// 不支持es6,使用common.js的方式導出
module.exports = {
fornatCount : fornatCount
}
```
2.在wxml文件中,通過wxs標簽引入wxs文件,類似script標簽
```
module:引入的模塊名,自定義,在標簽中使用
<wxs src="../../utils/format.wxs" module="format"></wxs>
```
3.使用方法
```
format:引入時自定義的模塊名
fornatCount:執行的方法名
<view class="count"> 播放:{{format.fornatCount(item.playCount) }}</view>
```
效果圖:
