Using useCssModule
return value in <style module>
#7732
Answered
by
seahindeniz
seahindeniz
asked this question in
Help/Questions
-
Hi, I'm trying to use CSS modules with CSS Grid but I'm stuck with the generated classnames. Using it from a css module inside of itself creates a problem. <script setup lang="ts">
import { useCssModule } from 'vue';
const modules = useCssModule();
</script>
<template>
<div :class="$style.grid">
<div :class="$style.item"></div>
</div>
</template>
<style module lang="scss">
.grid {
display: grid;
}
.item {
grid-area: v-bind(modules.item);
// or
// grid-area: v-bind($style.item);
}
</style> Is there any solution? |
Beta Was this translation helpful? Give feedback.
Answered by
seahindeniz
Feb 19, 2023
Replies: 1 comment
-
Thanks to @skirtles-code and their answers on Discord, I have found the solution There was a slightly different syntax that I've missed on docs. we need to wrap property path with quotes as mentioned in here https://vuejs.org/api/sfc-css-features.html#v-bind-in-css .item {
grid-area: v-bind('modules.item');
// or
// grid-area: v-bind('$style.item'); // works as the same
} And the final version is <template>
<div :class="$style.grid">
<div :class="$style.item"></div>
</div>
</template>
<style module lang="scss">
.grid {
display: grid;
}
.item {
grid-area: v-bind('$style.item');
}
</style> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
seahindeniz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to @skirtles-code and their answers on Discord, I have found the solution
There was a slightly different syntax that I've missed on docs. we need to wrap property path with quotes as mentioned in here https://vuejs.org/api/sfc-css-features.html#v-bind-in-css
And the final version is