uniapp 微信小程序 子组件中获取不到节点

uniapp yekong 1967℃

问题描述

uniapp微信小程序开发时,在子组件内获取节点使用wx.createSelectorQuery会报错,提示Cannot read property 'node' of undefined

wx.createSelectorQuery().selectAll('#c1').node(res => {
	console.log(res)
	const canvas = res[0].node
	const context = canvas.getContext('2d')

	canvas.width = 300
	canvas.height = 300

	lottie.setup(canvas)
	this.ani = lottie.loadAnimation({
		loop: true,
		autoplay: true,
		path: this.path,
		rendererSettings: {
			context,
		},
	})
	this._inited = true
}).exec()

解决办法

使用this.createSelectorQuery()代替wx.createSelectorQuery()就可以了。

喜欢 (3)