javascript - 為什麼一個類別沒有定義login方法和getUserInfo方法卻還能呼叫?
PHP中文网
PHP中文网 2017-06-26 10:57:41
0
2
644

在WxService中有下列語句:

class Service {
    ....没有找到login和getUserInfo的定义
    }
export default Service

在app.js中有以下語句:

import WxService from 'helpers/WxService'
APP({
    WxService: new WxService,
    getUserInfo() {
        return this.WxService.login()
        .then(data => {
            console.log(data)
            return this.WxService.getUserInfo()
        })
        .then(data => {
            console.log(data)
            this.globalData.userInfo = data.userInfo
            return this.globalData.userInfo
        })
    },
})

為什麼可以執行this.WxService.login()和this.WxService.getUserInfo()?

PHP中文网
PHP中文网

认证0级讲师

全部回覆(2)
phpcn_u1582

謝邀。

this.WxService是微信封裝的對象,對外是隱藏的。

ps:另外微信還有自己的協定weixin://類似http://

扔个三星炸死你

this.WxService是微信封裝的物件
https://mp.weixin.qq.com/debu...

wx.getUserInfo({
  success: function(res) {
    var userInfo = res.userInfo
    var nickName = userInfo.nickName
    var avatarUrl = userInfo.avatarUrl
    var gender = userInfo.gender //性别 0:未知、1:男、2:女
    var province = userInfo.province
    var city = userInfo.city
    var country = userInfo.country
  }
})
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!