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

154
Visualizações
vue - style not applied for extra component in same file

I added some style on .title and .description in my stylesheet for my test component, but not sure why the style not applied.

const test = Vue.component("test", {
  template: `<div class="test">
    <span class="title">{{title}}</span>
    <div class="description">{{description}}</div>
  </div>`,
  props: {
    id: Number,
    title: String,
    description: String,
  },
});

enter image description here

HelloWorld.vue

<template>
  <div id="hello">
    <test
      v-for="item in steps"
      :key="item.id"
      :id="item.id"
      :title="item.title"
      :description="item.description"
    />
  </div>
</template>

<script>
import Vue from "vue";

const test = Vue.component("test", {
  template: `<div class="test">
    <span class="title">{{title}}</span>
    <div class="description">{{description}}</div>
  </div>`,
  props: {
    id: Number,
    title: String,
    description: String,
  },
});

export default {
  components: {
    test,
  },
  data() {
    return {
      steps: [
        {
          id: 1,
          title: "What is Lorem Ipsum?",
          description:
            "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
        },
      ],
    };
  },
};
</script>
<style scoped lang="scss">
#hello {
  display: flex;
  flex-direction: column;
  .test {
    /* style applied */
    text-align: left;
    margin-top: 10px;
    .title {
      /* style not applied */
      font-size: 50px;
      color: orange;
    }
    .description {
      /* style not applied */
      font-size: 10px;
      line-height: 12px;
      color: red;
    }
  }
}
</style>

Codesandbox:
https://codesandbox.io/s/amazing-flower-rcvob?file=/src/components/HelloWorld.vue

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When using scoped styles, the styles will only apply to direct elements in the corresponding template. The title and description elements are child elements of the <test> component and are unaffected by scoped styles of another component.

You need to use ::v-deep if you want the style to apply to a child element of another component:

#hello {
  .test {
    &::v-deep .title {
      color: red;
    }
  }
}

I couldn't get this to work in codesandbox though. It might be a configuration issue. See also Deep Selectors.

about 4 years ago · Juan Pablo Isaza 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