uniapp开发微信小程序后,在微信小程序开发工具中组件样式失效问题

在用uniapp开发微信小程序之后,在微信小程序开发工具查看页面样式的时候,会出现组件元素找不到及样式失效的问题,最后发现是因为设置了虚拟化组件节点的原因,但是不推荐修改该属性,可以通过下面的方式从父组件传递样式
1

//父组件
<xxx customClass='className' customStyle='color:red;'></xxx>

//组件
<template>
    <view
        :class="[customClass]"
        :style="[customStyle]"
    >
        <slot />
    </view>
</template>
<script>
export default {
    name: 'xxx',	
    ...
    props: {
        // 从父组件传递的样式
        customStyle: {
            type: [Object, String],
            default: () => ({})
        },
        customClass: {
            type: String,
            default: ''
        },
    }
}
</script>
posted @ 2022-03-06 19:02  夜晚的斑马鱼  阅读(3307)  评论(0)    收藏  举报