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;
	}
}
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni-app组件修改样式无效可能有以下几个原因: 1、样式选择器错误:请确保你在修改样式文件时,选择器的书写正确,与要修改组件的类名或标签名一致。例如,如果要修改一个class为box的组件样式,那么选择器应该为`.box{}`。 2、样式覆盖问题:如果你在不同的地方同时修改了某个组件样式,而且在样式表中的先后顺序不同,后面的样式可能会覆盖前面的样式。因此,请检查一下是否存在样式覆盖的情况。 3、作用域问题uni-app中支持组件样式的作用域隔离,在组件中设置的样式只会影响到该组件内部,无法直接影响到组件外部的其他元素。如果你想修改组件外部的元素样式,可以考虑使用全局样式或者在组件内部使用`::v-deep`选择器。 4、样式继承问题:有些组件样式可能是继承了父级组件样式,因此你需要在父级组件样式中进行修改。审查元素,在浏览器的开发者工具中查看元素的样式继承关系,确定修改样式的位置。 5、缓存问题:有时候修改组件样式,但并没有立即生效,可能是因为uni-app样式文件有缓存。你可以尝试删除uni-app编译生成的`/unpackage`目录,并重新编译运行项目,看看样式是否生效。 总结来说,如果uni-app组件修改样式无效,你可以先检查选择器是否正确、样式是否被覆盖、是否遵循作用域规则,然后再查看样式继承关系、清除缓存等。如果问题仍然存在,可以通过uni-app的社区或官方文档获取更详细的帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值