app.js和app.wpy有什么不同呢?
答.app.wpy单文件包含了app.wxss\app.js\app.json\app.wxml
app.js
App({ /**
* 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
*/
onLaunch: function () { }, /**
* 当小程序启动,或从后台进入前台显示,会触发 onShow
*/
onShow: function (options) { }, /**
* 当小程序从前台进入后台,会触发 onHide
*/
onHide: function () { }, /**
* 当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
*/
onError: function (msg) { }
})
app.wpy
<style lang="less">
@import './font/iconfont.less';
page {
height: 100%;
background-color: #fff;
}
</style> <script>
import wepy from 'wepy';
import 'wepy-async-function'; export default class extends wepy.app {
config = {
pages: [
'pages/ep/ep',
'pages/forexpress',
'pages/bill/addone',
'pages/plan',
'pages/plan/clock',
'pages/bill',
'pages/me',
'pages/me/about',
'pages/me/planT',
'pages/me/billT',
'pages/index/index',
'pages/expressJump/expressJump',
'pages/share/share',
'pages/me/edit',
'pages/weather',
'pages/historytoday',
'pages/game/index',
'pages/testYun/index'
],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#138cff',
navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'white',
backgroundColor: '#138cff'
},
tabBar: {
color: '#757982',
selectedColor: '#138cff',
borderStyle: 'white',
backgroundColor: '#fff',
list: [
{
pagePath: 'pages/plan',
text: '计划',
iconPath: 'images/tabbar/plan.png',
selectedIconPath: 'images/tabbar/plan-on.png'
},
{
pagePath: 'pages/bill',
text: '账本',
iconPath: 'images/tabbar/bill.png',
selectedIconPath: 'images/tabbar/bill-on.png'
},
{
pagePath: 'pages/forexpress',
text: '快递',
iconPath: 'images/tabbar/index.png',
selectedIconPath: 'images/tabbar/index-on.png'
},
{
pagePath: 'pages/weather',
text: '天气',
iconPath: 'images/tabbar/weather.png',
selectedIconPath: 'images/tabbar/weather-on.png'
},
{
pagePath: 'pages/me',
text: '我的',
iconPath: 'images/tabbar/me.png',
selectedIconPath: 'images/tabbar/me-on.png'
}
]
}
}; globalData = {
userInfo: null,
info: {
name: 11
}
}; constructor() {
super();
this.use('requestfix');
this.use('promisify');
} onLaunch() {
this.testAsync();
Date.prototype.getWeek = function(days) {
let week = [
'星期天',
'星期一',
'星期二',
'星期三',
'星期四',
'星期五',
'星期六'
];
return week[new Date(this).getDay()];
};
} sleep(s) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('promise resolved....');
}, s * 1000);
});
} async testAsync() {
const data = await this.sleep(3);
console.log('打印数据:', data);
} getUserInfo(cb) {}
}
</script>