o***@qq.com
o***@qq.com
  • 发布:2019-06-12 19:51
  • 更新:2020-07-29 21:43
  • 阅读:16334

uni-app中微信小程序按钮无法获取用户信息,出现“GetUserInfo is not a function”错误。

分类:uni-app

** 各位兄弟,最近在学习Hcoder网站的“悦读”实例,里面有一个用uni-app写微信小程序登录,点击按钮显示登录信息。在uni-app的vue代码中这样写:**
<!-- #ifdef MP-WEIXIN -->
<button type="primary" open-type="getUserInfo" @getuserinfo="GetUserInfo">使用微信登录</button>
<!-- #endif -->

  export default {  
data() {  
	return {  
	}  
},  
methods:{  
	getUserInfo: function(res){  
		console.log(res);  
	}  
},  

 这里编译是没有错误信息的,但是到了微信小程序开发工具里,当点击按钮时,显示:  

thirdScriptError
_vm.GetUserInfo is not a function; [Component] Event Handler Error @ pages/login/login#handleEvent
Error: _vm.GetUserInfo is not a function
at http://127.0.0.1:11698/appservice/common/vendor.js:857:23
at Array.forEach (<anonymous>)
at http://127.0.0.1:11698/appservice/common/vendor.js:847:23
at Array.forEach (<anonymous>)
at H.handleEvent [as __e] (http://127.0.0.1:11698/appservice/common/vendor.js:837:17)
at Object.r.safeCallback (http://127.0.0.1:11698/appservice/dev/WAService.js:1:818220)
at http://127.0.0.1:11698/appservice/dev/WAService.js:1:959033
at f (http://127.0.0.1:11698/appservice/dev/WAService.js:1:964380)
at http://127.0.0.1:11698/appservice/dev/WAService.js:1:963487
at http://127.0.0.1:11698/appservice/dev/WAService.js:1:229997

** 请问这里到底是啥问题,尝试了几天,都不行。**

2019-06-12 19:51 负责人:无 分享
已邀请:
o***@qq.com

o***@qq.com (作者) - 70后IT男

谢谢解答,问题解决了!!

  • 1***@qq.com

    我也遇到了这个错误,不知道怎么回事啊,楼主能解答一下吗 0.0


    2019-07-08 17:44

  • ponyzhang

    回复 1***@qq.com:函数名字问题,正确格式:@getuserinfo="onGotUserInfo" ,事件里面的函数名一定用驼峰法命名


    2019-08-13 14:16

  • 9***@qq.com

    回复 ponyzhang: 驼峰命名也不行怎么说


    2020-04-19 08:55

DCloud_UNI_FXY

DCloud_UNI_FXY

注意自己模板里写的方法名的大小写

datena

datena

全都是小写不行
<button open-type="getUserInfo" type="primary" bindgetuserinfo="bindgetuserinfo">立即登录</button>

methods: {  
			  
			//微信小程序登录  
			bindgetuserinfo(res){  
				console.log("res: " + JSON.stringify(res));  
			},  
}
Fancye

Fancye

我也碰到这样的问题,@getuserinfo="userInfo" ,我也碰到同样的问题,函数名是驼峰形式的,但是还是报错找不到这个函数。

<!-- #ifdef MP-WEIXIN -->  
<button class="" open-type="getUserInfo" @getuserinfo="userInfo" withCredentials="true">微信授权获取用户信息</button>  
<!-- #endif -->  
  
methods: {  
			userInfo(){  
				if(!res.detail.iv){  
					uni.showToast({  
						title: "您取消了授权,登录失败!"  
					});  
					return false;  
				}  
				console.log('-------用户授权,并获取用户基本信息和加密数据------')  
				console.log(res.detail);  
			}  
}

报错信息:

thirdScriptError  
 _vm.userInfo is not a function; [Component] Event Handler Error @ pages/index/index#handleEvent  
Error:  _vm.wxGetUserInfo is not a function
8***@qq.com

8***@qq.com

我解决了,曲线救国
把需要用方法的地方组件化,通过引入组件,在组件内写一个原生方法就可以了。
不行的可以再找我QQ849230458

l***@163.com

l***@163.com

楼主就不能把如何解决的写出来吗?额,有点........

  • j***@163.com

    把写的回调函数放到methods: {}就可以了


    2020-03-13 12:29

1***@qq.com

1***@qq.com - 彭格列

楼主解决办法是啥??

CASWOO

CASWOO

同问楼主解决办法是啥??

5***@qq.com

5***@qq.com

大兄弟 咋解决的 快快如实招来 谢谢啊

2***@qq.com

2***@qq.com - 孜孜不倦的程序媛

我也遇到这个问题。
因为老师把methods方法写在 onLoad前面的。
照着老师的写。
结果就报这个错误。_vm.getUserInfo is not a function;

最后发现,因为文件生成时,下面已经有一个methods方法了。
两个methods方法,使用的后者,去掉后面那个就好了!

该问题目前已经被锁定, 无法添加新回复