- 开发无止境 -
Data: 2021-10-24 15:43:47Form: JournalClick: 10
module.exports
和 exports
模块化js示例:创建js公用文件 utils/common.js
function ouyangke(){
return '欧阳克';
}
function huangrong(){
return '黄蓉';
}
module.exports.ouyangke = ouyangke;
exports.huangrong = huangrong;
js示例:
const common = require('../../utils/common.js');
Page({
data: {
},
onLoad: function (options) {
console.log( common.ouyangke() );
console.log( common.huangrong() );
}
})
SWAN
可以通过import和include来引用模板文件import
<import src="./public.swan" />
<template is="person" data="{{array}}" />
<template name="person">
<view>
<text>ID: {{id}}</text>
<text>姓名: {{name}}</text>
</view>
</template>
Page({
data: {
array : {
id: 1,
name: '欧阳克'
}
}
})
include
data
里的数据<include src="header.swan"/>
<view> body </view>
<include src="footer.swan"/>