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>
相关推荐
To_OC40 分钟前
从 “卡死半天” 到 “打字机效果”:大模型流式输出前端实现全记录
前端·javascript·llm
rockey6271 小时前
基于AScript的JavaScript脚本语言发布啦
javascript·c#·.net·js·script
kyriewen2 小时前
我看完这篇安全论文——AI推荐的npm包,92%是编出来的
前端·javascript·ai编程
心中有国也有家2 小时前
AtomGit Flutter 鸿蒙客户端:Canvas 绘制进阶-路径、渐变与混合模式
android·javascript·flutter·华为·harmonyos
鹿目4 小时前
使用 Vant CLI 搭建 UI 组件库:从 H5 到小程序跨平台
前端·javascript
默_笙4 小时前
😭 我花了两小时找了一个数据结构 bug,才把"迷你 Cursor"跑起来,绝望(bushi)
前端·javascript
竹林8184 小时前
wagmi v2 监听合约事件踩坑记:从 `useContractEvent` 到 `watchContractEvent`,我重构了三版才搞定实时数据流
前端·javascript
甜味弥漫5 小时前
一文搞懂 Flex 弹性布局:为什么它成为现代 CSS 布局的首选?
css
xingcheng5 小时前
Vue 2 + JavaScript编码规范skill
javascript
Larcher5 小时前
从零实现一个可运行的 RAG - LangChain、内存向量库与检索增强生成
前端·javascript