对对的
对对的
  • 发布:2025-04-16 15:42
  • 更新:2025-04-16 15:58
  • 阅读:41

微信小程序无法自动为组件 ref 属性赋值(已解决)

分类:uni-app
<template>  
  <view>  
    <button @click="createOrder">微信支付</button>  
    <uni-pay ref="pay"></uni-pay>  
  </view>  
</template>  

<script setup>  
import { ref } from "vue";  

const pay = ref(null);  
const total_fee = ref(1);  

const createOrder = async () => {  
  // 发起支付  
  console.log('发起支付', pay.value);  
  const order_no = 'test' + Date.now();

尝试在 web 端和 微信小程序端,打印了 pay.value 的值,为什么在小程序端总是为 null,而在 web 端就一切正常。

是因为微信小程序无法为组件的 ref 属性赋值吗,还是需要做一些额外处理。

2025-04-16 15:42 负责人:无 分享
已邀请:
对对的

对对的 (作者)

将微信小程序和 hbuilderx 彻底关闭,重新打开后,再次运行就正常了

要回复问题请先登录注册