[英]Scss styling not applied to Vue component
I have an Img
component that consists of a figure with a nested image:我有一个
Img
组件,它由一个带有嵌套图像的图形组成:
<figure>
<img @dragstart="stopDrag" :src="src" />
</figure>
This component is used in another component, where I'm trying to overwrite the inner figure/image's style from the parent.该组件用于另一个组件,我试图从父组件覆盖内部图形/图像的样式。 The figure does get new styling, but the inner image does not.
该图确实获得了新的样式,但内部图像没有。
<template>
<List>
<li class="gridItem">
<Img :src="require('@/assets/images/girl.png')" />
</li>
</List>
<template>
...
<style scoped lang="scss">
.gridItem {
& figure {
width: 100%;
height: 100%;
//I did try & >>> img, and it didn't work.
& img {
width: auto;
}
}
}
</style>
The current version of this project is on my Github, so maybe it's easier to see the problem with a cloned repo?这个项目的当前版本在我的 Github 上,所以也许更容易看到克隆回购的问题? Github Repo
Github 回购
According to Vue own documentation根据Vue自己的文档
"Some pre-processors, such as Sass, may not be able to parse >>> properly. In those cases you can use the /deep/ or::v-deep combinator instead - both are aliases for >>> and work exactly the same." “某些预处理器,例如 Sass,可能无法正确解析 >>>。在这些情况下,您可以改用 /deep/ 或::v-deep 组合器 - 两者都是 >>> 的别名并且可以正常工作相同。”
So instead of & >>> img
do &::v-deep img
.所以代替
& >>> img
做&::v-deep img
。 I hope this fixes your issue.我希望这可以解决您的问题。
>>>
seem to have no effect for the Sass implementations I've tried, including node-sass
and sass
. >>>
似乎对我尝试过的 Sass 实现没有影响,包括node-sass
和sass
。 On the other hand, node-sass
and sass
still support /deep/
.另一方面,
node-sass
和sass
仍然支持/deep/
。
The following SCSS works for scoped styles with node-sass
4.14.1 and sass
1.26.9 :以下 SCSS 适用于具有
node-sass
4.14.1和sass
1.26.9 的范围 styles :
.gridItem {
& figure {
width: 100%;
height: 100%;
& /deep/ img {
width: 500px;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.