vue——样式穿透(深度选择器)/deep/ >>> ::v-deep 三者的区别
在项目中为了避免页面间样式污染常用scoped组件私有化,如果要改变element-ui的样式时需要用样式穿透才可复写样式。
/deep/
//在vue3.0之前可使用,例如(复写样式前加/deep/),vue3.0及后使用就会报错
/deep/ .el-input {
width: 60px;
}
::v-deep
//在vue3.0中已经废除,使用:deep(.a-button){color:red}
::v-deep .el-input {
width: 60px;
}
>>>
/*
只作用于css,对于less和scss不起作用,如果是less和scss的话需要用到/deep/或::v-deep
*/
>>> .el-input{
height:100px;
}
其他解决方式
//将 scoped 移除,或者新建一个没有 scoped 的 style(一个.vue文件允许多个style)
<style type="text/css">
.el-radio-button__inner {
width: 158px;
}
</style>