You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue 3/Vite中如何在scoped style标签中Glob导入CSS文件?

解决Vue组件scoped样式中Glob导入依赖模块CSS的问题

问题场景

需要在Vue组件的scoped <style>标签中,通过Glob语法从依赖模块导入CSS文件,概念代码如下:

<!-- myComponent.vue -->
<style scoped lang="less">
#myId {
  /* 默认情况下@import不支持Glob语法 */
  @import (less) 'foo_module/src/**/*.css'; 
}
</style>

<template>...</template>
<script>...</script>

尝试过两种方案但未成功:

  • 使用postcss-import-ext-glob插件,在vite.config.js中配置后,在组件中用@import-glob无效。
  • 使用import.meta.glob获取到了CSS字符串,但无法注入到scoped <style>中(模板插值在
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 14:32:53