MCPcopy
hub / github.com/vuejs/core / useCssModule

Function useCssModule

packages/runtime-dom/src/helpers/useCssModule.ts:4–31  ·  view source on GitHub ↗
(name = '$style')

Source from the content-addressed store, hash-verified

2import { EMPTY_OBJ } from '@vue/shared'
3
4export function useCssModule(name = '$style'): Record<string, string> {
5 if (!__GLOBAL__) {
6 const instance = getCurrentInstance()!
7 if (!instance) {
8 __DEV__ && warn(`useCssModule must be called inside setup()`)
9 return EMPTY_OBJ
10 }
11 const modules = instance.type.__cssModules
12 if (!modules) {
13 __DEV__ && warn(`Current instance does not have CSS modules injected.`)
14 return EMPTY_OBJ
15 }
16 const mod = modules[name]
17 if (!mod) {
18 __DEV__ &&
19 warn(`Current instance does not have CSS module named "${name}".`)
20 return EMPTY_OBJ
21 }
22 return mod as Record<string, string>
23 } else {
24 /* v8 ignore start */
25 if (__DEV__) {
26 warn(`useCssModule() is not supported in the global build.`)
27 }
28 return EMPTY_OBJ
29 /* v8 ignore stop */
30 }
31}

Callers 2

setupFunction · 0.90

Calls 2

getCurrentInstanceFunction · 0.90
warnFunction · 0.90

Tested by 1

setupFunction · 0.72