上一章已经讲过了:deep(),其实还有两个选择器可以补充
1.插槽选择器
A 组件定义一个插槽
<template><div>我是插槽<slot></slot></div></template><script>export default {}</script><style scoped></style>
在App.vue 引入
<template><div><A><div class="a">私人定制div</div></A></div></template><script setup>import A from "@/components/A.vue"</script><style lang="less" scoped></style>
在A组件修改class a 的颜色
<style scoped>.a{color:red}</style>
无效果
默认情况下,作用域样式不会影响到
解决方案 slotted
<style scoped>:slotted(.a) {color:red}</style>
2.全局选择器
在之前我们想加入全局 样式 通常都是新建一个style 标签 不加scoped 现在有更优雅的解决方案
<style>div{color:red}</style><style lang="less" scoped></style>
<style lang="less" scoped>:global(div){color:red}</style>
3.动态 CSS
单文件组件的
