找了一下文档,发现可使用wxs文件解决javascript
文档地址:https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxs/html
经过使用wxs文件,实如今wxml页面中调用自定义的JavaScript函数java
具体思路:函数
使用到wxs文件,而后在wxs文件里面添加numberToFix函数;而后在须要使用numberToFix方法的wxml页面引入该wxs文件,而后就能够经过{{numberToFix(persent)}}这种方式调用了
code
1# 建立一个numbertofix.wxs文件,建立numberToFix函数xml
var filter = { numberToFix: function (value) { return value.toFixed(1) } } module.exports = { numberToFix: filter.numberToFix }
2# 在须要使用numberToFix函数的页面引入numbertofix.wxs文件htm
<wxs module="filter" src="../../utils/numbertofix.wxs"></wxs>
3# 调用便可ip
<text class="vote-item-data-percent">{{filter.numberToFix(item.vote_count/vote.data.voters_count*100)}}%</text>