(\s*$)/g, "");
}
//最下面一定要加上你自定义的方法(作用:将模块接口暴露出来),否则会报错:util.trim is not a function;
module.exports = {
IsChinese: IsChinese,
trim: trim
}
//test.js
var util = require('../../utils/util.js');
Page({
onLoad: function () {
console.log("判断是否为中文:"+util.IsChinese('测试'));
console.log("去除左右空格:" + util.trim(s));
}
})在开发者工具的 Console可以看到

注意了,在util.js里的 Regular()方法,我们不可以这样调用util.Regular(),因为我们没有用 module.exports 来暴露模块接口
如果直接 调用则会出现这样的错误
thirdScriptError
util.Regular is not a function;at "pages/test/test" page lifeCycleMethod onLoad function
TypeError: util.Regular is not a function以上就是微信小程序如何引用公共js里的方法分享的详细内容,更多请关注php中文网其它相关文章!
小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜一下即可打开应用。
关键词:微信小程序如何引用公共js里的办法分享