在wxml頁面中,只能在插值{{ }}中寫簡單的js表達式,而不能調用方法,例如想取出一個字符串的最后一位,就不能調用slice()方法
util.wxs文件
// .wxs文件 function indexOf(arr, value) { if (arr.indexOf(value) < 0) { return false; } else { return true; } } module.exports.indexOf = indexOf;
wxml文件
// 引入 tools可自定義名稱 <wxs src="../../utils/util.wxs" module="tools" /> // 使用 <view>{{tools.indexOf([1, 2, 3, 6, 9], 6) ? '包含' : '不包含'}}</view>
原文:https://blog.csdn.net/qq_34568700/article/details/111043327