我是靠谱客的博主 爱笑菠萝,这篇文章主要介绍vue3全局组件中使用全局样式失效bug,现在分享给大家,希望可以做个参考。

正常代码如下

<template>
  <div class="client-1000 flex-column">
    <HeaderSearch />
  </div>
</template>

<script setup>
</script>

<style lang="scss" scoped>
.client-1000 {
  height: 100%;
  background: #fff;
}
</style>

HeaderSearch 组件

<template>
  <el-row>
    <el-col :span="10" class="flex-acenter">
      <div class="flex-acenter">
        <span>title</span>
        <el-input />
      </div>
    </el-col>
  </el-row>
</template>

<script>
/* 组件名字 */
export default {
  name: 'HeaderSearchInfo'
};
</script>

<script setup>
</script>

<style lang="scss" scoped>
</style>

解决方案:

  1. 在你的组件里面写一个样式,任何样式都行,因为不写没触发编译(这个是最优解)
  2. 父级样式去掉scope(别这样搞)
<template>
  <el-row>
    <el-col :span="10" class="flex-acenter">
      <div class="flex-acenter">
        <span>title</span>
        <el-input />
      </div>
    </el-col>
  </el-row>
</template>

<script>
/* 组件名字 */
export default {
  name: 'HeaderSearchInfo'
};
</script>

<script setup>
</script>

<style lang="scss" scoped>
/* 重点就是这里 */
.xxxxxxxxxxxxxxxxxxx{
}
</style>

最后

以上就是爱笑菠萝最近收集整理的关于vue3全局组件中使用全局样式失效bug的全部内容,更多相关vue3全局组件中使用全局样式失效bug内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(103)

评论列表共有 0 条评论

立即
投稿
返回
顶部