How to pass styles to child component and use it as scoped style in Vue?

后端 未结 2 682
谎友^
谎友^ 2021-01-17 13:32

I have a parent component:





        
相关标签:
2条回答
  • 2021-01-17 13:54

    You can directly set your styles prop to inline style v-bind:style instead of scoped style. Hope it will work.

    <template>     
    <p v-bind:style="styles">Hello World</p>
    </template>
    
    0 讨论(0)
  • 2021-01-17 13:56

    If you want to target the child elements with scoped styling you have to use the deep selector.

    Which can be done with

    a >>> b { color : red; }
    /deep/ a b { color : red; }
    a::v-deep b { color : red; }
    

    Here is the full explanation: https://vue-loader.vuejs.org/guide/scoped-css.html#child-component-root-elements

    0 讨论(0)
提交回复
热议问题