File tree 3 files changed +46
-8
lines changed
Filter options
3 files changed +46
-8
lines changed
Original file line number Diff line number Diff line change @@ -10,13 +10,8 @@ const { compileStyle } = compiler
10
10
const StylePostLoader : LoaderDefinitionFunction = function ( source , inMap ) {
11
11
const query = qs . parse ( this . resourceQuery . slice ( 1 ) )
12
12
13
- // skip normal CSS files without scoped flag
14
- if (
15
- ! ( 'vue' in query ) ||
16
- query . type !== 'style' ||
17
- ! query . id ||
18
- ! query . scoped
19
- ) {
13
+ // skip normal CSS files
14
+ if ( ! ( 'vue' in query ) || query . type !== 'style' || ! query . id ) {
20
15
this . callback ( null , source , inMap )
21
16
return
22
17
}
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" text" >hello</div >
3
+ </template >
4
+
5
+ <script >
6
+ export default {
7
+ data () {
8
+ return {
9
+ color: ' red' ,
10
+ font: {
11
+ size: ' 2em' ,
12
+ },
13
+ }
14
+ },
15
+ }
16
+ </script >
17
+
18
+ <style >
19
+ .text {
20
+ color : v-bind(color );
21
+
22
+ /* expressions (wrap in quotes) */
23
+ font-size : v-bind(' font.size' );
24
+ }
25
+ </style >
Original file line number Diff line number Diff line change @@ -198,4 +198,22 @@ test('CSS Modules Extend', async () => {
198
198
expect ( style ) . toContain ( `.${ instance . $style . red } {\n color: #FF0000;\n}` )
199
199
} )
200
200
201
- test . todo ( 'experimental <style vars>' )
201
+ test ( 'v-bind() in CSS' , async ( ) => {
202
+ const { window, instance } = await mockBundleAndRun ( {
203
+ entry : 'style-v-bind.vue' ,
204
+ } )
205
+
206
+ const shortId = genId ( 'style-v-bind.vue' )
207
+ const style = normalizeNewline (
208
+ window . document . querySelector ( 'style' ) ! . textContent !
209
+ )
210
+
211
+ expect ( style ) . toMatch ( `color: var(--${ shortId } -color);` )
212
+ expect ( style ) . toMatch ( `font-size: var(--${ shortId } -font\\.size);` )
213
+
214
+ const computedStyle = window . getComputedStyle ( instance . $el )
215
+ // Because the tests run in JSDOM, we can't directly get the computed `color` value.
216
+ // To get around this, we test the corresponding CSS variable instead.
217
+ expect ( computedStyle . getPropertyValue ( `--${ shortId } -color` ) ) . toBe ( 'red' )
218
+ expect ( computedStyle . getPropertyValue ( `--${ shortId } -font.size` ) ) . toBe ( '2em' )
219
+ } )
You can’t perform that action at this time.
0 commit comments