标签:extends component 第三方 body global back 全局 create port
react中的css在一个文件中导入,是全局的,对其他组件的标签都会有影响。
使用styled-components第三方模块来解决
npm i styled-components
import {createGlobalStyle} from ‘styled-components‘;
export const GlobalStyled = createGlobalStyle`
body{
margin:0;
padding:0;
background:red;
}`
import React from ‘react‘; import {GlobalStyled} from ‘./style.js‘; class App extends React.Components{ render(){ return( <div className=‘App‘> <GlobalStyled /> </div> ) } }
styled-components:公共css编程组件内部css的插件
标签:extends component 第三方 body global back 全局 create port
原文地址:https://www.cnblogs.com/shengjunyong/p/12077971.html