n***@126.com
n***@126.com
  • 发布:2023-09-19 18:33
  • 更新:2023-09-19 20:27
  • 阅读:376

在页面中调用自定义组件,微信小程序中无法正常显示

分类:uni-app

uniapp开发微信小程序,自定义组件如下:
<template>
<view class="container">
<view class="role-image">
<image class="role-image" :src="imgUrl"></image>

    </view>  
    <view class="content">  
        <view class="role-name">  
            {{roleName}}  
        </view>  

        <view class="dialog" style="padding: 10px 10px 10px 10px;" >  
            <rich-text :nodes="text"></rich-text>  
        </view>  
    </view>  
</view>  

</template>

<script>
export default {
name:"heyi",
props:{
imgUrl:{
type:String,
default:'../../static/logo.png'
}
,
roleName:{
type:String,
default:'意义'
},
text:{
type:String,
default:'<p>好了,开始奇妙<br>的探险之旅吧</p>'
}

        },  
    data() {  
        return {  

        };  
    }  
}  

</script>
在页面中调用该组件
<template>
<view>
<heyi :imgUrl="imgu" :roleName="rn" :text = "tt"></heyi>
</view>
</template>

<script>
import heyi from '@/components/heyi/heyi.vue'

export default {  
    data() {  
        return {  
            imgu:'../../static/green-arrow.png',  
            rn:'张三',  
            tt:'hello,world!'  
        }  
    },  
    methods: {  
    }  
}  

</script>
在微信小程序中无法正常显示,在h5中显示正常。以上代码为简化后的,源代码中还有点击事件@tap,报WASubContext.js?t=wechat&s=1695109052747&v=3.0.2:1 Component "components/c_dialog/c_dialog" does not have a method "__e" to handle event "tap".

2023-09-19 18:33 负责人:无 分享
已邀请:
DCloud_UNI_Anne

DCloud_UNI_Anne

建议新建空项目单独测试看看,如果确认是框架问题可以提供最小化示例(上传附件)【咨询问题/bug处理优先级规则】:https://ask.dcloud.net.cn/article/38139

  • n***@126.com (作者)

    已单独新建空项目并上传,麻烦您抽空看一下。除了不显示,还发现在uniapp中的{{roleName}},运行到微信开发工具中会变成{{''+roleName+''}},然后屏幕显示undefined

    2023-09-19 20:11

n***@126.com

n***@126.com (作者)

已上传

DCloud_UNI_Anne

DCloud_UNI_Anne

1.可以去掉手动引入 import heyi from '@/components/heyi/heyi.vue';,因为components 目录结构遵循 easycom 规范会自动引入

2.如果不使用easycom,手动引用和注册vue组件,需要加上components 参考文档


export default {  
        components:{  
            heyi  
        }  
    }

要回复问题请先登录注册