uniapp组件深度修改样式问题

Posted qq_43628158

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uniapp组件深度修改样式问题相关的知识,希望对你有一定的参考价值。

问题一:样式类型scss/less/css

如果公共样式为common.scss
对应的App.vue文件必须加上lang=“scss”

<style lang="scss">
	/*每个页面公共css */
	@import "@/common/css/common.scss";
	page
</style>

问题二:深入修改样式

①当前页面修改,带scoped,css样式;

<style scoped>
/* #ifndef MP-WEIXIN */
.index_list_bar >>> .uni-section
	background-color:#fff;
	margin:0px; 
	font-weight:700; 
	height:80rpx;

/* #endif */
</style>

备注:对子组件样式不生效;且微信小程序会报错,需使用条件编译作区分

②当前页面修改,带scoped,css样式/scss样式

<style scoped>
/deep/ .index_list_bar .uni-section
	background-color:#fff;
	margin:0px; 
	font-weight:700; 
	height:80rpx;

</style>
<style lang="scss" scoped>
/deep/ .index_list_bar
	.uni-section
		background-color:#fff;
		margin:0px; 
		font-weight:700; 
		height:80rpx;
	

</style>
<style lang="scss" scoped>
/deep/ .index_list_bar .uni-section
	background-color:#fff;
	margin:0px; 
	font-weight:700; 
	height:80rpx;

</style>

备注:子组件,h5,APP,小程序均可生效

③当前页面修改,带scoped,scss样式;

<style lang="scss" scoped>
::v-deep .index_list_bar
	.uni-section
		background-color:#fff!important;
		margin:0px!important; 
		font-weight:700!important; 
		height:80rpx!important;
	

</style>

备注:子组件亦能生效;h5生效,但APP无效

④common.scss公共样式中

::v-deep .index_list_bar
	.uni-section
		background-color:#fff!important;
		margin:0px!important; 
		font-weight:700!important; 
		height:80rpx!important;
	

备注:APP不生效,H5及微信小程序、子组件均生效

总结:可使用第四种方法,APP使用条件编译语句在需修改样式的页面配合②一起使用

//common.scss
::v-deep .index_list_bar
	.uni-section
		background-color:#fff!important;
		margin:0px!important; 
		font-weight:700!important; 
		height:80rpx!important;
	


//index.vue首页中
/deep/ .index_list_bar
	.uni-section
		background-color:#fff;
		margin:0px; 
		font-weight:700; 
		height:80rpx;
	

以上是关于uniapp组件深度修改样式问题的主要内容,如果未能解决你的问题,请参考以下文章

uniapp和graceUI介绍

uni-app基础组件介绍

关于微信小程序原生组件与uniApp混合开发过程遇到的问题与解决方式

uni-app 自定义修改底部tabBar

uni-app 引用 微信小程序原生自定义组件

微信小程序原生工程转uni-app工程