在學習寫微信小程序的同學注意了,別給官方扯蛋的示例給坑了!


官方的示例代碼簡直TMD扯蛋,如下的寫法:

Page({
  data: {
    userInfo: {}
  },
  callPhone: function (event) {
    wx.makePhoneCall({
      phoneNumber: '15814256793',
    })
  },
  onShareAppMessage: function () {
    return {
      title: '關於我們',
      path: '/pages/about/about'
    }

  },
  map: function (event) {
    wx: wx.navigateTo({
      url: '../map/map',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  }
})

建議的寫法應當如下:

function getConfig(){
  var config={};
  config.data={
    userInfo: {}
  };

  config.callPhone=function (event) {
      wx.makePhoneCall({
        phoneNumber: '15814256793',
      })
  };

  config.onShareAppMessage=function () {
    return {
      title: '關於我們',
      path: '/pages/about/about'
    }
  };

  config.map=function (event) {
    wx: wx.navigateTo({
      url: '../map/map',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  };
  return config;
}

Page(getConfig());

需要命理預測服務請加微信:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章