welcome

《微信小程序》在wxml中使用函数

在wxml中使用函数有两种方法

 

方法一:在wxml中直接添加模块,就可以在wxml中直接引用,举个例子

<wxs module="func">
  module.exports = {
    // *星号替换
    strSplit: function (value) {
      value = value.toString();
      var str = '';
      str = value.substring(0, 3) + '****' + value.substring(7, value.length);
      return str;
    }
  }
</wxs>

<text>{{func.strSplit(12345678901)}}</text>

 

方法二:新建wxs文件,在文件中写入函数,举个例子

//  .wxs文件
var strReplace = function (value) { // *号替换 value = value.toString(); var str = ''; str = value.substring(0, 3) + '****' + value.substring(7, value.length); return str; } module.exports = { strReplace: strReplace }

 

<!-- .wxml文件 -->

<!-- 引入 -->
<wxs src="../../utils/filter.wxs" module="filter" />

<!-- 调用 -->
<text>{{filter.strReplace(12345678901)}}</text>

 

posted @ 2020-04-01 16:17  一首弦曲献仙音  阅读(1164)  评论(0编辑  收藏  举报
//博文图片放大缩小 //飘桃花效果