lz_0618
lz_0618
  • 发布:2021-04-06 12:14
  • 更新:2022-09-14 09:55
  • 阅读:1099

【报Bug】组件放置在分包中this.$refs获取不到对象

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 3.1.7

第三方开发者工具版本号: stable wechat_devtools_1.05.2103190_x64

基础库版本号: 2.16.0

项目创建方式: HBuilderX

示例代码:
<template> <view> <tki-qrcode cid="qrcode1" ref="qrcode" :val="val" :size="size" :unit="unit" :background="background" foreground="foreground" :pdground="pdground" :icon="icon" :iconSize="iconsize" :lv="lv" :onval="onval"

loadMake="loadMake" :usingComponents="true" @result="qrR" />

<view @click="onClicked">点我</view>  

</view>
</template>

<script>
import QrCode from '@/components/tki-qrcode/tki-qrcode.vue'

export default {  
    data() {  
        return {  
            // clientHeight: 0,  

            val: '121212121221', // 要生成的二维码值  
            size: 500, // 二维码大小  
            unit: 'upx', // 单位  
            background: '#FFFFFF', // 背景色  
            foreground: '#000000', // 前景色  
            pdground: '#32dbc6', // 角标色  
            icon: '', // 二维码图标  
            iconsize: 40, // 二维码图标大小  
            lv: 3, // 二维码容错级别 , 一般不用设置,默认就行  
            onval: true, // val值变化时自动重新生成二维码  
            loadMake: true, // 组件加载完成后自动生成二维码  
            src: '', // 二维码生成后的图片地址或base64  
            // timerId: null,  
            // interval: 29 * 1000,  
        };  
    },  
    components: {  
        QrCode  
    },  
    onLoad(options) {  
        this.$refs.qrcode._makeCode();  
    },  
    methods: {  
        onClicked() {  
            this.$refs.qrcode._makeCode();  
        },  
        /*二维码生成回调*/  
        qrR(res) {  
            console.log('qrR')  
            this.src = res  
        },  
    }  
}  

</script>

<style lang="scss">

</style>

操作步骤:

1,将tki-qrcode组件从主包移动到分包;
2,在分包页面中使用组件;
3.在页面中调用that.$refs.qrcode._makeCode();出错

预期结果:

that.$refs.qrcode._makeCode()或this.$refs.qrcode._makeCode()调用正常

实际结果:

that.$refs.qrcode._makeCode(),报that.$refs.qrcode为undefined

bug描述:

当组件放置在分包中时,使用this.$refs获取不到自定义组件!使用插件市场的二维码插件https://ext.dcloud.net.cn/plugin?id=39,出现的问题,导致that.$refs.qrcode._makeCode();出错。当主包和分包都有该插件时或者只有主包中有该插件时,没有问题。

2021-04-06 12:14 负责人:无 分享
已邀请:
xuyujian

xuyujian

这个问题,最后怎么解决的?我也遇到同样的问题了/

g***@tocs.cn

g***@tocs.cn - shonve

同样的问题,没人知道什么原因吗

要回复问题请先登录注册