question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Child component doesn't merge className from parent.

See original GitHub issue

Vue.js version

2.1.4

Reproduction Link

https://jsfiddle.net/JounQin/s5b79kqc/

Steps to reproduce

Just look at the output HTML

What is Expected?

Child comp should has className abc def

What is actually happening?

The className is abc abc def

Is that by design?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
fnlctrlcommented, Dec 4, 2016

Sorry but I don’t really understand your use case, that seems over-engineering to me. If you really need to bind a static class abc twice (once in component’s template, once in parent’s template, as shown in your fiddle), you or the build system is probably doing something wrong.

0reactions
JounQincommented, Dec 4, 2016

@yyx990803 actually it does not.

However, there is a problem when using vue-loader which makes me to use composes.

Consider two component:

// BaseComp.vue

<template>
  <div :class="$style.base">
    BaseComp.vue
  </div>
</template>
<style module>
  .base{
    color: red;
    background-color: green;
  }
</style>
// Hello.vue

<template>
  <BaseComp :class="$style.hello"/>
</template>
<script>
  import BaseComp from './BaseComp.vue'

  export default {
    name: 'hello',
    components: {
      BaseComp
    }
  }
</script>
<style module>
  .hello {
    color: blue;
    background-color: pink;
  }
</style>

Obviously I want to override the style of .base, but actually it does not work because the style of BaseComp.vue is loaded after Hello.vue……

http://test.1stg.me/

Read more comments on GitHub >

github_iconTop Results From Across the Web

React passing additional classNames to child component in ...
In this case, I would like the Child component div to have the "flavor" prop, and also have both classes "parent-class" and "child-class"....
Read more >
Pass class names as props to React components | bobbyhadz
To pass class names as props to a React component, pass a string containing the class names as a prop. Destructure the prop...
Read more >
Building React Components Using Children Props ... - Soshace
As you can see, the onOk handler needs merging, while visible and onCancel props are just passed from parent context. In this code...
Read more >
When does React re-render components? - Felix Gerschau
When the state changes in the parent component (in this case, App ), the two Tile components will re-render, even though the second...
Read more >
React Tips — Fix Common Errors, Multiple Classes, and ...
In this article, we'll look at some tips for writing better React apps. Add Multiple Classes to a React Component. We can use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found