简体   繁体   中英

how to pass style css from parent component to child component vue

My Parent:

<template>
   <div> 
     <p class="my-class">Hello world.</p>
     <Child/>
 </div>
<template>

import Child from "@/components/Child.vue";

<style scoped>
  .my-class{
    font-size: 18px;
  }
</style>

What'd be the child vue? to load scoped style CSS in my Child.Vue component.

You can use the deep selector in scoped css block to apply the class to the component's children components. See the docs

In your case the css portion of the SFC would turn to something along the lines of:

<style scoped>
::v-deep(.my-class) {
  font-size: 18px;
}
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM