javascript - Why can a class still call it even if it does not define the login method and getUserInfo method?
PHP中文网
PHP中文网 2017-06-26 10:57:41
0
2
675

There are the following statements in WxService:

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

There are the following statements in 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
        })
    },
})

Why can this.WxService.login() and this.WxService.getUserInfo() be executed?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
phpcn_u1582

Thanks for the invitation.

This.WxService is the object packaged by WeChat and is hidden from the outside world.

ps: In addition, WeChat has its own protocol weixin:// similar to http://

扔个三星炸死你

this.WxService is the object packaged by Weixin
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
  }
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!