miniprograme-wsx

由于小程序不支持在渲染的时候使用函数方法
所以需要借助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

猜你喜欢

转载自www.cnblogs.com/cyany/p/10083938.html