【微信小程序】报错TypeError: this.setData is not a function

2020年2月13日 0次阅读 共913个字 0条评论 0人点赞 QueenDekimZ

WX Developer Kits Debug
	open() {
	this.setData({
	camera: true,
	login_res: "登录中..."
	})
	type = "takePhoto";
	let ctx = wx.createCameraContext(this)
	let that = this
	time = setInterval(function () {
	if (type == "takePhoto") {
	console.log("begin takephoto")
	ctx.takePhoto({
	quality: "normal",
	success: (res) => {
	console.log(res.tempImagePath)
	var tempImagePath = res.tempImagePath
	wx.uploadFile({
	url: 'http://192.168.43.236:90/face_login',
	filePath: tempImagePath,
	name: 'file',
	header: { "Content-type": "multipart/form-data" },
	success: function (res) {
	if (res.data == "success") {
	type = "endPhoto";
	that.setData({
	login_res: "登录成功"
	})}
	},
	})
	}
	})
	}
	}, 200)
	setTimeout(function () {
	clearInterval(time);
	type = "endPhoto";
	this.setData({
	login_res: "登陆超时"
	})
	}, 5000)
	},

this.setData只能用于函数里面的第一层,如果用于函数里面的其他方法内,比如此处的setInterval里面,就必须要在函数内第一层申明this,
比如that=this

setTimeout()函数改为

setTimeout(function () {
	clearInterval(time);
	type = "endPhoto";
	that.setData({
	login_res: "登陆超时"
	})
	}, 5000)

后,成功编译。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值