Home  >  Q&A  >  body text

javascript - In the vue.js component development model, how to make the style only apply to this component and its subcomponents.

If scoped is used, the style can only affect the current component but not its sub-components. Sometimes due to design problems, there are a lot of styles shared between different sub-components. I want to ask the master if the style can only be applied to This component and its subcomponents.

怪我咯怪我咯2730 days ago935

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-05-18 10:53:18

    Don’t use scoped and take control of the css namespace yourself

    You can name each component with a specific and unique class, and the CSS of the component is within the scope of this naming.

    For example, header is a subcomponent of index

        .header-comp{
            h2{
                
            }
            .title{
            
            }
        }
    
        .index-view{
            .container{
            
            }
        }

    Final rendering

        <p class="index-view">
            <p class="header-comp"></p>
        </p>
        .index-view{}
        .index-view xxx{}
        .header-comp{}
        .hader-comp .xxxx{}

    reply
    0
  • Cancelreply