Asi*_*eed 1 font-face reactjs styled-components
这就是我在Reactjs中加载字体文件的方式
import styled from 'styled-components';
import fontUrls from './UberMove-Bold.ttf';
import fontUrls1 from './UberMove-Light.ttf';
import fontUrls2 from './UberMove-Medium.ttf';
import fontUrls3 from './UberMove-Regular.ttf';
const Fonts = styled`
@font-face {
font-familty: 'UberMove-Light';
src: url(${fontUrls1}) format('truetype');
}`;
Run Code Online (Sandbox Code Playgroud)
导入时抛出错误
未捕获的错误:无法创建组件的样式组件:@ font-f .ace {font-familty:'UberMove-Light'; src:url(,)format('truetype');}。
You need to load the font-face globally and then use it in the components:
import { createGlobalStyle } from "styled-components";
const GlobalStyles = createGlobalStyle`
body {
@import url(${fontUrls1});
font-family: 'UberMove-Light';
}
`
const App = () => (
<div>
<GlobalStyles />
//...
</div>
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45 次 |
| 最近记录: |