Skip to content

Commit 2ddead0

Browse files
authored
fix: useCSSModule to adapt the change of getCurrentInstance, close #620 (#622)
* fix(useCssModule): adapting the behavior of `useCSSModule` to the change of `getCurrentInstance`. close #620 * chores: add test for `useCssModule`.
1 parent 4b2f1ab commit 2ddead0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/apis/useCssModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const useCSSModule = (name = '$style'): Record<string, string> => {
1212
return EMPTY_OBJ
1313
}
1414

15-
const mod = (instance as any)[name]
15+
const mod = (instance.proxy as any)?.[name]
1616
if (!mod) {
1717
__DEV__ &&
1818
warn(`Current instance does not have CSS module named "${name}".`)

test/apis/useCssModule.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const Vue = require('vue/dist/vue.common.js')
2+
const { useCSSModule } = require('../../src')
3+
4+
const style = { whateverStyle: 'whateverStyle' }
5+
6+
function injectStyles() {
7+
Object.defineProperty(this, '$style', {
8+
configurable: true,
9+
get: function () {
10+
return style
11+
},
12+
})
13+
}
14+
15+
describe('api/useCssModule', () => {
16+
it('should get the same object', (done) => {
17+
const vm = new Vue({
18+
beforeCreate() {
19+
injectStyles.call(this)
20+
},
21+
template: '<div>{{style}}</div>',
22+
setup() {
23+
const style = useCSSModule()
24+
return { style }
25+
},
26+
})
27+
vm.$mount()
28+
expect(vm.style).toBe(style)
29+
done()
30+
})
31+
})

0 commit comments

Comments
 (0)