在uniapp使用vue3进行开发时,使用了uni-popup弹框,但是在对弹框进行操作的时候,发现调用this.$refs.xxx.close()报错Cannot read property '$refs' of undefined
解决方案如下

<template>
	<uni-popup ref="popupCoupon" type="bottom">
		xxx
	</uni-popup>
</template>
<script setup>
import { ref } from 'vue';
import uniPopup from '@/components/uni-popup/uni-popup.vue';
const popupCoupon = ref(null)
popupCoupon.value.open()
setTimeout(()=>{
	popupCoupon.value.close()
},1000)
</script>

使用ref声明一下就可以正常使用了

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐