CSS Modules let us use the variable in both CSS and JS.
// use in temaplate
...
...<p :class="{ [$style.red]: isRed }">Am I red?</p>
// use in js
...
...
<script>
export default {
created () {
console.log(this.$style.red)
// -> "red_1VyoJ-uZ"
// an identifier generated based on filename and className.
}
}
</script>
/// use in css preprocessor
...
...
<style lang="stylus" module>
.red {
color: red;
}
</style>
We can get the variable no matter in template, JS or CSS. But if we have some feature like: click and change all website's "main-color" which define in CSS.
Can we change the variable in JS?
$style.red: truejust adds a class red to your element. And in your css you can do.red { color: red }