k***@126.com
k***@126.com
  • 发布:2023-12-18 11:05
  • 更新:2024-03-11 21:56
  • 阅读:370

【报Bug】Vue3 uni-popup支付宝小程序获取不到 ref

分类:uni-app

产品分类: uniapp/小程序/阿里

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 13.3.1

HBuilderX类型: 正式

HBuilderX版本号: 3.98

第三方开发者工具版本号: 3.7.9

基础库版本号: 2.9.5

项目创建方式: HBuilderX

示例代码:
<script setup>  
import { STATIC_HOST } from '@/config.js'  
import { onLoad } from '@dcloudio/uni-app'  
import { ref, reactive, onMounted } from 'vue'  
import { upload, modify } from '@/api/index.js'  
import { to } from '@/utils/utils.js'  
import { useUserStore } from '../../stores/user'  

const userStore = useUserStore()  
const inputDialog = ref()  
const changeAvatar = ref()  

const _this = reactive({  
    userName: 'xx昵称',  
    img_main: {  
        fileID: 1,  
        url: STATIC_HOST + '/avatar.png'  
    },  
    avatar_url: ''  
})  

const inputDialogToggle = () => {  
    inputDialog.value.open()   
}  
const dialogInputConfirm = (val) => {  
    uni.hideLoading()  
    _this.userName = val  
    inputDialog.value.close()  
}  

const getAvatar = () => {  
    changeAvatar.value.choose()  
}  

const select = async (e) => {  
    const res = await upload({  
        filePath: e.tempFilePaths[0]  
    })  
    if (res.code === 0) {  
        _this.img_main.url = res.data.viewUrl  
        _this.avatar_url = res.data.url  
    }  
}  

const submit = async () => {  
    const res = await modify({  
        avatar: _this.avatar_url,  
        nickname: _this.userName  
    })  

    if (res.code === 1) {  
        userStore.nickname = _this.userName  
        userStore.avatar = _this.img_main.url  
        to('/pages/my/index')  
        uni.showToast({  
            title: res.msg,  
            icon: 'none'  
        })  
    }  
}  

onLoad(() => {  
    _this.userName = userStore.nickname  
    _this.img_main.url = userStore.avatar  
})  

onMounted(() => {})  
</script>  

<template>  
    <bqContainer>  
        <view class="body">  
            <uni-list :border="false">  
                <uni-list-item link title="头像" :border="false">  
                    <template v-slot:footer>  
                        <image class="slot-image" :src="_this.img_main.url" mode="widthFix" @click="getAvatar" />  
                    </template>  
                </uni-list-item>  

                <uni-list-item link title="昵称" :border="false" @click="inputDialogToggle" :rightText="_this.userName" />  
            </uni-list>  

            <view class="btn-box">  
                <button @click="submit">保存</button>  
            </view>  
        </view>  
        <uni-popup ref="inputDialog" id="inputDialog" type="dialog">  
            <uni-popup-dialog mode="input" title="请输入昵称" :value="_this.userName" @confirm="dialogInputConfirm" />  
        </uni-popup>  
        <view v-show="false">  
            <uni-file-picker  
                ref="changeAvatar"  
                limit="1"  
                :del-icon="false"  
                disable-preview  
                file-mediatype="image"  
                @select="select"  
                @success="success" />  
        </view>  
    </bqContainer>  
</template>  

<style lang="scss" scoped>  
.body {  
    display: flex;  
    flex-direction: column;  
    align-items: center;  
    box-sizing: border-box;  
    padding-top: 45rpx;  
}  

:deep(.uni-list) {  
    width: 100vw;  
    background-color: transparent;  
}  

:deep(.uni-list-item) {  
    margin-bottom: 10rpx;  
    // #ifdef MP-ALIPAY  
    padding-right: 20rpx;  

    .uni-icons {  
        margin-left: 10rpx;  
    }  

    // #endif  
}  

:deep(.uni-list-item__container) {  
    display: flex;  
    align-items: center;  
}  

:deep(.uni-list-item__content-title) {  
    font-size: 30rpx;  
    font-weight: 400;  
    color: #030505;  
}  

.slot-image {  
    width: 118rpx;  
    height: 118rpx;  
    min-height: 118rpx;  
}  

:deep(.uni-list-item__extra-text) {  
    font-size: 28rpx;  
    font-weight: 400;  
    color: #777b83;  
}  

.btn-box {  
    margin-top: 140rpx;  

    button {  
        width: 680rpx;  
        height: 98rpx;  
        line-height: 98rpx;  
        background: #2f71ff;  
        border-radius: 49rpx;  
        font-size: 32rpx;  
        font-weight: 500;  
        color: #ffffff;  

        &::after {  
            border: none;  
        }  
    }  
}  
</style>

操作步骤:

"""
const inputDialogToggle = () => {
console.log(inputDialog.value) // null
inputDialog.value.open()
}
"""

预期结果:

"""
const inputDialogToggle = () => {
console.log(inputDialog.value) // 不为 null
inputDialog.value.open()
}
"""

实际结果:

"""
const inputDialogToggle = () => {
console.log(inputDialog.value) // null
inputDialog.value.open()
}
"""

bug描述:

2023-12-18 11:05 负责人:YUANRJ 分享
已邀请:
9***@qq.com

9***@qq.com

找到解决方案了, 参考 https://blog.csdn.net/ITzhongzi/article/details/127076158 使用 nextTick 处理

DCloud_UNI_HRK

DCloud_UNI_HRK

目前与同事跟进后,排查出来不是BUG,您是否使用了支付宝小程序的component2 编译模式?项目根目录下是否含有mini.project.json覆盖掉了原本的配置,如果可以的话,请提供一下问题工程

  • 9***@qq.com

    我也遇到同样的问题,请问怎么解决

    2024-03-11 20:27

  • DCloud_UNI_HRK

    回复 9***@qq.com: 看看支付宝编译出来的mini.project.json是怎么样的

    2024-03-11 20:48

  • 9***@qq.com

    回复 DCloud_UNI_HRK:

    内容如下

    {

    "format": 2,

    "compileOptions": {

    "component2": true,

    "enableNodeModuleBabelTransform": true,

    "globalObjectMode": "enable"

    },

    "developOptions": {

    "lazyCompile": true,

    "hotReload": true

    }

    }

    2024-03-11 21:00

DCloud_UNI_OttoJi

DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信

使用下面 demo 地址未能复现你的问题

https://gitcode.net/xiurensha5731/uni-app-questions/-/blob/q/componet-ref/src/pages/index/index.vue

在支付宝小程序中点击昵称后,模拟器 和 真机调试都可以唤起弹窗输入框,请提供更多信息

9***@qq.com

9***@qq.com

我也遇到同样的问题,请问怎么解决。这是我的支付宝项目配置

要回复问题请先登录注册