<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 属性赋值吗,还是需要做一些额外处理。
1 个回复
对对的 (作者)
将微信小程序和 hbuilderx 彻底关闭,重新打开后,再次运行就正常了