在用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>
