1.自定义外部js
bar.js
Page({
...
})
function toAbout() {
...
}
module.exports = {
toAbout //或 toAbout:toAbout
}
注意:
自定义方法应该写在Page外部,才能直接在exports中写入方法名称。
2.导入js
index.js
Page({
toAbout:function() {
var barjs = require('../../template/bar/bar')
barjs.toAbout()
},
})
可能出现的问题:
Error: APP-SERVICE-Engine:Please do not register multiple Pages in pages/index/index.js
原因:
var barjs = require(’…/…/template/bar/bar’) 写在Page外部导致index.js出现多个Page
解决方法:
将 var barjs = require(’…/…/template/bar/bar’) 移入Page内部