Browse Source

refactor: 将登录逻辑中的data定义移到wx.login回调内

将data对象的定义从wx.login外部移到内部回调函数中,避免可能的变量作用域问题
master
前端-胡立永 3 weeks ago
parent
commit
538a7fd955
1 changed files with 12 additions and 11 deletions
  1. +12
    -11
      pages/index/index.vue

+ 12
- 11
pages/index/index.vue View File

@ -175,19 +175,20 @@
// ...
let self = this
let data = {
code: res.code
}
if (uni.getStorageSync('shareId')) {
data.shareId = uni.getStorageSync('shareId')
}
wx.login({
success(res) {
success(e) {
// console.log(res.code,'code')
if (res.code) {
if (e.code) {
let data = {
code: e.code
}
if (uni.getStorageSync('shareId')) {
data.shareId = uni.getStorageSync('shareId')
}
self.$api('wxLogin', data, res => {
console.log(res, 'login')
if (res.code == 200) {


Loading…
Cancel
Save