Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style-vars-2 v-bind feature doesn't work with Composition API #3688

Closed
Sackeys opened this issue Apr 28, 2021 · 2 comments
Closed

Style-vars-2 v-bind feature doesn't work with Composition API #3688

Sackeys opened this issue Apr 28, 2021 · 2 comments
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working scope: sfc

Comments

@Sackeys
Copy link

Sackeys commented Apr 28, 2021

Version

3.0.11

Reproduction link

https://codesandbox.io/s/epvsl

Steps to reproduce

With the following template:

<template>
  <div class="bloc">{{ size }} {{ color }}</div>
</template>

<script>
  // Component script
</script>

<style scoped>
.bloc {
  width: v-bind(size);
  height: v-bind(size);
  background-color: v-bind(color);
}
</style>

1 - Create a component using dynamic CSS style based on the Options API.

export default {
  data: () => {
    return {
      size: "100px",
      color: "green"
    }
  }
}

2 - Create a component using dynamic CSS style based on the Composition API.

export default {
  setup() {
    const
      size = "100px",
      color = "red"

    return {
      size,
      color
    }
  }
}

What is expected?

CSS v-bind feature should work using both Options and Composition API.

What is actually happening?

CSS v-bind feature doesn't work with the Composition API.
The following error is printed:

Uncaught (in promise) ReferenceError: _unref is not defined
    __injectCSSVars__
    setVars
@Sackeys Sackeys changed the title Style-vars-2 fails with Composition API Style-vars-2 doesn't work with Composition API Apr 28, 2021
@Sackeys Sackeys changed the title Style-vars-2 doesn't work with Composition API Style-vars-2 v-bind feature doesn't work with Composition API Apr 28, 2021
@HcySunYang HcySunYang added 🐞 bug Something isn't working 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Apr 28, 2021
@chukwumaokere
Copy link

chukwumaokere commented Aug 19, 2021

I'm having this very issue running vue 3.2.4
package.json: "vue": "^3.2.4"

<script>
export default {
...
  setup(){
...
    let boardThemeLight = Themes.cpc_board_theme[0]; // Themes.cpc_board_theme is just a basic array ['#646372','#353340']
    let boardThemeDark = Themes.cpc_board_theme[1]; // ['#646372','#353340']
...
    return{ 
    ...
    boardThemeLight,
    boardThemeDark
    }
...
  }
}
</script>

<style scoped>
#board1 :deep(.white-1e1d7) {
   /* background-color: #646372;*/
   background-color: v-bind(boardThemeLight);
    @apply text-purple-50;
  }
#board1 :deep(.black-3c85d) {
   /* background-color: #353340;*/
    @apply text-purple-50;
  }
<style>

Error in browser:

Uncaught (in promise) ReferenceError: _unref is not defined
    at eval (Game2.vue?72e0:228)
    at setVars (runtime-dom.esm-bundler.js?830f:673)
    at callWithErrorHandling (runtime-core.esm-bundler.js?5c40:6990)
    at callWithAsyncErrorHandling (runtime-core.esm-bundler.js?5c40:6999)
    at ReactiveEffect.getter [as fn] (runtime-core.esm-bundler.js?5c40:7346)
    at ReactiveEffect.run (reactivity.esm-bundler.js?a1e9:160)
    at flushPostFlushCbs (runtime-core.esm-bundler.js?5c40:7191)
    at flushJobs (runtime-core.esm-bundler.js?5c40:7228)

If I remove this v-bind, I don't get this error but then I don't get the desired effect of having state driven CSS

@chukwumaokere
Copy link

chukwumaokere commented Aug 19, 2021

I'm having this very issue running vue 3.2.4
package.json: "vue": "^3.2.4"

<script>
export default {
...
  setup(){
...
    let boardThemeLight = Themes.cpc_board_theme[0]; // Themes.cpc_board_theme is just a basic array ['#646372','#353340']
    let boardThemeDark = Themes.cpc_board_theme[1]; // ['#646372','#353340']
...
    return{ 
    ...
    boardThemeLight,
    boardThemeDark
    }
...
  }
}
</script>

<style scoped>
#board1 :deep(.white-1e1d7) {
   /* background-color: #646372;*/
   background-color: v-bind(boardThemeLight);
    @apply text-purple-50;
  }
#board1 :deep(.black-3c85d) {
   /* background-color: #353340;*/
    @apply text-purple-50;
  }
<style>

Error in browser:

Uncaught (in promise) ReferenceError: _unref is not defined
    at eval (Game2.vue?72e0:228)
    at setVars (runtime-dom.esm-bundler.js?830f:673)
    at callWithErrorHandling (runtime-core.esm-bundler.js?5c40:6990)
    at callWithAsyncErrorHandling (runtime-core.esm-bundler.js?5c40:6999)
    at ReactiveEffect.getter [as fn] (runtime-core.esm-bundler.js?5c40:7346)
    at ReactiveEffect.run (reactivity.esm-bundler.js?a1e9:160)
    at flushPostFlushCbs (runtime-core.esm-bundler.js?5c40:7191)
    at flushJobs (runtime-core.esm-bundler.js?5c40:7228)

If I remove this v-bind, I don't get this error but then I don't get the desired effect of having state driven CSS

Resolved.

I realized that when i updated to vue 3.2.4 my devDependency for compiler-sfc did NOT automatically update so i had to manually run
npm install -D @vue/compiler-sfc for it to manually update to 3.2.4 to match with my vue version which allowed v-bind to work.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working scope: sfc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants