feat(sfc): css modules support

This commit is contained in:
Evan You
2019-12-17 21:28:24 -05:00
parent abfea8eb45
commit d84cf3a538
5 changed files with 39 additions and 3 deletions

View File

@@ -0,0 +1,23 @@
import { getCurrentInstance } from '../component'
import { EMPTY_OBJ } from '@vue/shared'
import { warn } from '../warning'
export function useCSSModule(name = '$style'): Record<string, string> {
const instance = getCurrentInstance()!
if (!instance) {
__DEV__ && warn(`useCSSModule must be called inside setup()`)
return EMPTY_OBJ
}
const modules = instance.type.__cssModules
if (!modules) {
__DEV__ && warn(`Current instance does not have CSS modules injected.`)
return EMPTY_OBJ
}
const mod = modules[name]
if (!mod) {
__DEV__ &&
warn(`Current instance does not have CSS module named "${name}".`)
return EMPTY_OBJ
}
return mod as Record<string, string>
}