wepy - 與原生有什么不同(app.js和app.wpy比較)


 

app.js和app.wpy有什么不同呢?

答.app.wpy單文件包含了app.wxss\app.js\app.json\app.wxml

 

app.js

 1 App({  2 
 3   /**  4  * 當小程序初始化完成時,會觸發 onLaunch(全局只觸發一次)  5    */
 6   onLaunch: function () {  7     
 8  },  9 
10   /** 11  * 當小程序啟動,或從后台進入前台顯示,會觸發 onShow 12    */
13   onShow: function (options) { 14     
15  }, 16 
17   /** 18  * 當小程序從前台進入后台,會觸發 onHide 19    */
20   onHide: function () { 21     
22  }, 23 
24   /** 25  * 當小程序發生腳本錯誤,或者 api 調用失敗時,會觸發 onError 並帶上錯誤信息 26    */
27   onError: function (msg) { 28     
29  } 30 })

 

 

 

 

app.wpy

 1 <style lang="less">
 2 @import './font/iconfont.less';  3 page {  4   height: 100%;  5   background-color: #fff;  6 }  7 </style>
 8 
 9 <script>
 10 import wepy from 'wepy';  11 import 'wepy-async-function';  12 
 13 export default class extends wepy.app {  14   config = {  15  pages: [  16       'pages/ep/ep',  17       'pages/forexpress',  18       'pages/bill/addone',  19       'pages/plan',  20       'pages/plan/clock',  21       'pages/bill',  22       'pages/me',  23       'pages/me/about',  24       'pages/me/planT',  25       'pages/me/billT',  26       'pages/index/index',  27       'pages/expressJump/expressJump',  28       'pages/share/share',  29       'pages/me/edit',  30       'pages/weather',  31       'pages/historytoday',  32       'pages/game/index',  33       'pages/testYun/index'
 34  ],  35  window: {  36       backgroundTextStyle: 'light',  37       navigationBarBackgroundColor: '#138cff',  38       navigationBarTitleText: 'WeChat',  39       navigationBarTextStyle: 'white',  40       backgroundColor: '#138cff'
 41  },  42  tabBar: {  43       color: '#757982',  44       selectedColor: '#138cff',  45       borderStyle: 'white',  46       backgroundColor: '#fff',  47  list: [  48  {  49           pagePath: 'pages/plan',  50           text: '計划',  51           iconPath: 'images/tabbar/plan.png',  52           selectedIconPath: 'images/tabbar/plan-on.png'
 53  },  54  {  55           pagePath: 'pages/bill',  56           text: '賬本',  57           iconPath: 'images/tabbar/bill.png',  58           selectedIconPath: 'images/tabbar/bill-on.png'
 59  },  60  {  61           pagePath: 'pages/forexpress',  62           text: '快遞',  63           iconPath: 'images/tabbar/index.png',  64           selectedIconPath: 'images/tabbar/index-on.png'
 65  },  66  {  67           pagePath: 'pages/weather',  68           text: '天氣',  69           iconPath: 'images/tabbar/weather.png',  70           selectedIconPath: 'images/tabbar/weather-on.png'
 71  },  72  {  73           pagePath: 'pages/me',  74           text: '我的',  75           iconPath: 'images/tabbar/me.png',  76           selectedIconPath: 'images/tabbar/me-on.png'
 77  }  78  ]  79  }  80  };  81 
 82   globalData = {  83     userInfo: null,  84  info: {  85       name: 11
 86  }  87  };  88 
 89  constructor() {  90  super();  91     this.use('requestfix');  92     this.use('promisify');  93  }  94 
 95  onLaunch() {  96     this.testAsync();  97     Date.prototype.getWeek = function(days) {  98       let week = [  99         '星期天', 100         '星期一', 101         '星期二', 102         '星期三', 103         '星期四', 104         '星期五', 105         '星期六'
106  ]; 107       return week[new Date(this).getDay()]; 108  }; 109  } 110 
111  sleep(s) { 112     return new Promise((resolve, reject) => { 113       setTimeout(() => { 114         resolve('promise resolved....'); 115       }, s * 1000); 116  }); 117  } 118 
119  async testAsync() { 120     const data = await this.sleep(3); 121     console.log('打印數據:', data); 122  } 123 
124  getUserInfo(cb) {} 125 } 126 </script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM