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".
n***@126.com (作者)
已单独新建空项目并上传,麻烦您抽空看一下。除了不显示,还发现在uniapp中的{{roleName}},运行到微信开发工具中会变成{{''+roleName+''}},然后屏幕显示undefined
2023-09-19 20:11