问题一:样式类型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;
}
}
补充:从 HBuilderX 4.56+ ,vue2 项目也将默认使用 dart-sass 预编译器;sass的预处理器,/deep/被报错,需修改语法;
/deep/ 替换成 ::v-deep
如果您希望继续使用node-sass,可以在manifest.json根节点配置: “sassImplementationName”: “node-sass”; 可选值 “dart-sass” | “node-sass”。
默认manifest.json是不进行此项配置的,会根据HBuilderX版本自动选择;
//manifest.json
{
"name" : "应用名称",
"appid" : "__UNI__E775F19",
"description" : "应用描述",
"versionName" : "1.0.0",
"sassImplementationName" : "node-sass",
...
...
"app-plus" : {}
}