So, I've read here that in Vue.js, you can use /deep/
or >>>
in a selector in order to create style rules that apply to elements inside of child components. However, attempting to use this in my styles, whether in SCSS or in plain old CSS, doesn't work. Instead, they are sent to the browser verbatim, and therefore have no effect. For example:
home.vue:
<style lang="css" scoped>
.autocomplete >>> .autocomplete-input
{
// ...
}
</style>
generated css:
<style type="text/css">
.autocomplete >>> .autocomplete-input[data-v-2bda0c9a]
{
//...
}
</style>
what I want:
<style type="text/css">
.autocomplete[data-v-2bda0c9a] .autocomplete-input
{
//...
}
</style>
My webpack configuration pertaining to vue-loader
looks like this:
// ...
{
test: /\.vue$/,
loader: "vue-loader",
options: {
loaders: {
scss: "vue-style-loader!css-loader!sass-loader"
}
}
}
// ...
So my question is, how do I get this >>>
operator to work?
I've already found this answer, but I'm doing exactly that and it doesn't work...
Use ::v-deep
The accepted answer wasn't working for me in scoped
SASS/SCSS, but ::v-deep
did:
::v-deep .child-class {
background-color: #000;
}
If you're not using SASS/SCSS, use the >>>
syntax:
>>> .child-class {
background-color: #000;
}
With either ::v-deep
or >>>
, the <style>
tag for this component must be scoped
:
<style scoped>
EDIT (10/1/2019): Extra info :
/deep/
syntax is being deprecatedsass
and dart-sass
do not support /deep/
, only node-sass
does/deep/
(since it does not support node-sass
)