Vue3新增加的css语法糖

一、deep
复制代码
<template>
    <div class="">
        <el-input /> 
    </div>
</template>
<style scoped>
/* 样式穿透 */
:deep input {
    background: red;
}
</style>
二、slotted

子组件修改插槽里面的样式

复制代码
<template>
    <div class="">
        <child>
            <div></div>
        </child>
    </div>
</template>

<style scoped>
/* 修改插槽样式 */
:slotted(div) {
    background: red;
}
</style>
三、global

scoped里面依然可以写全局样式

复制代码
<template>
    <div class="">

    </div>
</template>
<style scoped>
/* 全局样式 */
:global(div) {
    background: red;
}
</style>
四、v-bind
复制代码
<template>
    <div class="">

    </div>
</template>
<script setup lang="ts">
import { ref } from "vue"
const bag = ref<string>('red')
</script>
<style scoped>
/* 动态样式*/
div {
    background: v-bind(bag)
}
</style>
五、module
复制代码
<!-- 将生成的 CSS 类作为 $style 对象的键暴露给组件 -->
<template>
    <div :class="$style.title"></div> 
</template>

<style module>
.title {
    color: red;
}
</style>

<!-- 将生成的 CSS 类作为 jx 对象的键暴露给组件-->
<template>
   <div :class="jx.title"></div> 
</template>
<style module="jx">
.title {
    color: red;
}
</style>

可以通过获取

复制代码
<script setup lang="ts">
import { useCssModule } from "vue"
const jx = useCssModule('jx')
console.log(jx.title);
const user = `<div class="${jx.title}">12313</div>`
</script>
<style module="jx">
.title {
    color: red;
}
</style>
相关推荐
默_笙2 小时前
🏛 给 AI 配一间办公室:Harness Engineering 六大模块与它的实现
前端·javascript
linux_cfan4 小时前
videojs v10 源代码系列解读:14 · 谓词守卫:在运行时安全地调用能力
前端·javascript·音视频
+VX:Fegn08955 小时前
计算机毕业设计|基于springboot + vue旅游管理系统(源码+数据库+文档)
java·开发语言·vue.js·spring boot·课程设计
雪芽蓝域zzs5 小时前
第 7 章:双 Y 轴组合图(柱状 + 折线,看板高频场景)
vue.js·echars
一 乐6 小时前
二手交易平台|基于springboot + vue二手交易平台(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序
天若有情6736 小时前
【纯前端小工具】公历生日转农历,批量查询每年农历生日对应的公历日期(GitHub Pages在线直接用)
前端·javascript·github pages·农历转换·lunisolar·网页小工具
vx-程序开发6 小时前
【计算机毕设】django校园跑腿服务系统83141
java·数据库·vue.js·spring boot·spring·elasticsearch·django
林语琛7 小时前
我写的 switch…break 被 Babel 偷偷吞了
前端·javascript·babel
liuchangng7 小时前
Jev 模型研究:从生成式大模型到决策式模型——System One、RLCD 校准与采用边界
java·javascript·人工智能·python·深度学习
一 乐7 小时前
养老院管理系统|基于springboot + vue养老院管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·毕业设计