在实际项目开发过程中,出现在uniapp中对组件样式进行了修改,但是运行到微信小程序却失效,以下是经验总结
1.使用的拓展组件,如(uni-data-checkbox)
可以在methods同级使用styleIsolation配合/deep/或者::v-deep可实现样式修改
options: {
styleIsolation: 'shared'
},
/deep/ .uni-data-checklist .checklist-group .checklist-box.is--default.is-checked .radio__inner{
border-color: #957636;
}
2.非拓展组件,而是原生组件,如(checkbox)
上述方法并不适用,需要在app.vue文件中使用以下代码,若是h5页面,无需在 #ifdef APP-PLUS || MP-WEIXIN */
/* #ifdef APP-PLUS || MP-WEIXIN */
checkbox .wx-checkbox-input{
border: 2rpx solid #957636 !important;
border-radius: 50% !important;
width: 32rpx !important;
height: 32rpx !important;
}
checkbox .wx-checkbox-input.wx-checkbox-input-checked{
color: #fff !important;
background-color:#957636 !important;
border:none !important;
width: 36rpx !important;
height: 36rpx !important;
}
/* checkbox:not([disabled]) .wx-checkbox-input:hover{
border-color: #957636;
} */
checkbox .wx-checkbox-input.wx-checkbox-input-checked:before{
font-size: 30rpx;
}
radio .wx-radio-input.wx-radio-input-checked{
background-color: #1485EE !important;
border-color: #1485EE !important;
background-clip: content-box !important;
padding: 6rpx!important;
box-sizing: border-box;
}
/**
* 去除选中后的对号
*/
radio::before{
content: '' !important;
}
/* #endif */
实现:
其他组件大体类似,或许还有其他解决方案,可分享交流