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