Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
Why css is not applied for a component of one app into another app in vue

Hi i have situation where css and scss is not applied of a component of 1 app into another app

I have 2 apps

  1. core
  2. plugins

i want to use the components of a core app into plugins app

here is how i'm doing

Core App

//main.js

import "bootstrap/dist/css/bootstrap.min.css";
const app1 = new Vue({
    render: h => h(App),
    ....
})

//core.component.vue

<template>
   .....
</template>
<script>
   export default{
       name:'CoreComponent',
       ....
    }
</script>
<styles lang="scss" scoped>
   $bgColor:red;   <--- these css are not applied when used in app 2
   ...             <--- these css are not applied when used in app 2
</styles>

Core provides component mappers for providing component when requested to plugins.

//core-component-mapper.js

export default{
  CoreComponent: require('path/CoreComponent.vue').default,
}

Below my plugins App setup

import "bootstrap/dist/css/bootstrap.min.css";
import CoreComponentMapper 'path/core-component-mapper.js'

const app2 = new Vue({
    render: h => h(App),
    components:{
      FirstCoreComp: CoreComponentMapper.CoreComponent,
    },
})

Note: please ignore any mistake in my demo code, code works perfectly in my setup except user defined css is not applied

Question: whichever css is defined on component of app 1 i,e core by me is not applied when used in App 2 i,e plugins

Note: i did not setup any webpack config i guess my both vue app is using default vue-loader config

Intresting thing is that bootstrap css works don't know why.(it is used in both the apps)

@MatJ as you asked in one of your comment i'm attaching screenshot (as per me css are not merged , but inline css are applied well)

enter image description here

enter image description here

Please help me thanks in advance!!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It looks like the css that are not being applied are inside a scoped block:

<style lang="scss" scoped>

and this is exactly how scoped css in vue are supposed to work.

If you wish to have a common shared style, just put the variables you need in a separate .css file and import it like you do with the bootstrap css.

over 4 years ago · Santiago Trujillo Relatório

0

Here is an article explaining properly all the solutions that are available with Vue3 style tag.

Here, you could either:

  • remove scoped from your style tag (it's not styles btw)
  • inject some global CSS coming from another file higher in the app
  • use the new :global(.your-query-selector) selector.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda