由于小程序不支持在渲染的时候使用函数方法
所以需要借助wsx处理
var gainLen = function(data){return data.length;}var sliceWord = function(data){return data.slice(0,20)+"...";}module.exports = {gainLen :gainLen,sliceWord: sliceWord};
然后在需要使用的wxml里面就添加
<wxs src="../../utils/tools.wxs" module="tools" />使用的时候用{{tools.sliceWord(item.desc)}}
Reference:https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxs/01wxs-module.html