N
N
Nubbb2021-08-09 20:37:30
Vue.js
Nubbb, 2021-08-09 20:37:30

How can styles be used globally in a module?

How can classes from global styles be used in a module?

<template>
  <a href="/" :class="$style.appLogo"> <AppLogo /> </a>
   <span :class="$style.btnText">Войти</span>
</template>

<script lang="ts">
import { defineComponent } from '@nuxtjs/composition-api'
import AppLogo from '@/static/icons/app/logo.svg?inline'
export default defineComponent({
  components: {
    AppLogo,
  },
})
</script>

<style module lang="scss">
.app {
  &Logo {
    color: $fontColor;
    font-weight: 900;
    font-size: 26px;
    line-height: 44px;
    display: flex;
    align-items: center;
    svg {
      width: 40px;
      height: 47px;
      margin-right: 9px;
    }
  }
}
</style>


and in nuxt.config.js there is a global css

// Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    '@/assets/styles/desktop/button.scss',
  ],


How can I use styles from css files in a component?

Or can it be done somehow differently so that all classes are hashed during assembly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Grigory S., 2021-08-09
@Grigory90

https://github.com/css-modules/css-modules#exceptions

D
Danila, 2021-08-09
@Machinez

Alternatively, you can import the desired file with styles

<template>
  <a href="/" :class="$style.appLogo"> <AppLogo /> </a>
   <span :class="$global.btnText">Войти</span>
</template>

<style module lang="scss">
.app {
  &Logo {
    color: $fontColor;
  }
}
</style>

<style lang="scss" module="$global" src="@/assets/styles/desktop/button.scss" />

the classes of the button.scss file will be available in the $global object (you can put your own name)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question