// .van-field__body 父盒子
.test {
:deep(.van-field__body) {
.van-field__control {
font-size: 17px;
}
}
}
.box ::v-deep .box-inner {
background-color: pink;
}
<style>
.test/deep/{
margin-top:10px
}
</style>
setup() {
return {
themeColor: `'linear-gradient(225deg, rgba(0, 215, 252, 1) 0%, rgba(66, 133, 244, 1) 100%)'`
}
}
<style lang='scss'>
.test{
background:v-bind(themeColor);
}
</style>
<style scoped>
.a :deep(.b) {
/* 要穿透的样式代码 */
}
</style>
默认情况下,作用域样式不会影响到 <slot/> 渲染出来的内容,因为它们被认为是父组件所持有并传递进来的。使用 :slotted 伪类以确切地将插槽内容作为选择器的目标:
<style scoped>
:slotted(div) {
color: red;
}
</style>
如果想让其中一个样式规则应用到全局,比起另外创建一个 <style>,可以使用 :global 伪类来实现:
<style scoped>
:global(.red) {
color: red;
}
</style>
1、 默认以$style 对象暴露给组件;
<template>
<p :class="$style.red">
This should be red
</p>
</template>
<style module>
.red {
color: red;
}
</style>
2、可以自定义注入module名称
<template>
<p :class="classes.red">red</p>
</template>
<style module="classes">
.red {
color: red;
}
</style>
单文件组件的 <style> 标签可以通过 v-bind 这一 CSS 函数将 CSS 的值关联到动态的组件状态上:
<script setup>
const theme = {
color: 'red'
}
</script>
<template>
<p>hello</p>
</template>
<style scoped>
p {
color: v-bind('theme.color');
}
</style>
注入的类可以通过 useCssModule API 在 setup() 和