Skip to content

Styles only applied to root element #15

@AustinGil

Description

@AustinGil

When creating a live Vue component with styles, it looks like this plugin generates the markup and gives the root component a unique data attribute. Styles are then generated for this component based on that attribute as follows:

Original Vue component:

<template>
  <div class="parent">
    <div class="child"></div>
  </div>
</template>
<style>
.parent {
  background: red;
}
.child {
  background: blue;
}
</style>

Output HTML

<div class="parent" data-v-3ebe6f67>
  <div class="child"></div>
</div>

Output styles

.parent[data-v-3ebe6f67] {
  background: red;
}
.child[data-v-3ebe6f67] {
  background: blue;
}

A data attribute is added to the root element in the example, and the same data attribute is added to the style block rules.

This works fine for the root element, but any nested element with the child class does not properly get styled because the added data attribute interferes.

There two solutions I can think of would be to remove the data attribute or add it to every nested HTML element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions