- <template>
- <div class="">
- <el-input />
- </div>
- </template>
- <style scoped>
- /* 样式穿透 */
- :deep input {
- background: red;
- }
- </style>
子组件修改插槽里面的样式
- <template>
- <div class="">
- <child>
- <div></div>
- </child>
- </div>
- </template>
-
- <style scoped>
- /* 修改插槽样式 */
- :slotted(div) {
- background: red;
- }
- </style>
scoped里面依然可以写全局样式
- <template>
- <div class="">
-
- </div>
- </template>
- <style scoped>
- /* 全局样式 */
- :global(div) {
- background: red;
- }
- </style>
- <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>
- <!-- 将生成的 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>