wxLogin() { uni.login ({ provider:"weixin", success:function(r) { console.log('wxLogin::success:', r,this) let that = this return request ({ 'url': 'addons/ball/user/wxlogin', headers: { isToken: false }, 'method': 'post', 'data': {code:r.code} }). then( rs => { console.log('wxLogin::request.then:', JSON.stringify(rs)) uni.setStorageSync('userinfo', JSON.stringify(rs) ) uni.setStorageSync('token', r.code) /*let option ={}; if (option['data']) { // option['data']['token'] = rs.data.data.token } else { //option['data'] = { token: rs.data.data.token } } */ this.$tab.navigateTo('pages/work/index') //uni.reLaunch({url:'/pages/work/index'}) }.bind(this)) }.bind(this) } ) //let arr_users = {} //wxLogin( arr_users ) }, 语法错误: Unexpected token, expected "," (119:6),错误在哪?
时间: 2024-04-17 12:25:39 浏览: 22
在你提供的代码中,语法错误位于第119行的最后一行代码 `)` 前面。错误提示为 "Unexpected token, expected ','",意思是意外的标记,期望逗号。
这个错误的原因是,你在 `uni.login()` 方法的回调函数中,使用了箭头函数的语法,但是箭头函数的语法错误。箭头函数应该使用 `=>` 符号而不是 `function` 关键字。
要修复这个问题,请将 `success: function(r) {` 改为 `success: (r) => {`,并确保其后的代码都在箭头函数的代码块内部。修改后的代码如下:
```javascript
wxLogin() {
uni.login({
provider: "weixin",
success: (r) => {
console.log('wxLogin::success:', r, this);
let that = this;
return request({
'url': 'addons/ball/user/wxlogin',
headers: {
isToken: false
},
'method': 'post',
'data': { code: r.code }
})
.then(rs => {
console.log('wxLogin::request.then:', JSON.stringify(rs));
uni.setStorageSync('userinfo', JSON.stringify(rs));
uni.setStorageSync('token', r.code);
this.$tab.navigateTo('pages/work/index');
//uni.reLaunch({url:'/pages/work/index'})
});
}
});
}
```
请注意,修改后的代码中使用了箭头函数 `(r) => { ... }` 来定义 `success` 回调函数,这样就可以正确地访问到外部的 `this`。
希望这个解答对你有所帮助!如果你还有其他问题,请随时提问。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)