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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM