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