您需要做两件事:
.scss
导入每个页面。(重要:请阅读上面链接中有关getInitialProps
在_app.js
文件中定义的注释).scss
以该body
元素为目标的文件。默认情况下,它已margin: 8px;
应用样式-您将要覆盖它。然后import
将此.scss
文件放入_app.js
文件中。工作代码和邮箱:
pages / _app.js
import React from "react";
import App from "next/app";
import Head from "next/head";
import "../styles/index.scss";
class MyApp extends App {
// remove this 'getInitialProps' if you don't plan on render blocking
// for example, signing a user in before the requested page is loaded
static async getInitialProps({ Component, ctx }) {
return {
pageProps: {
...(Component.getInitialProps
? await Component.getInitialProps(ctx)
: {})
}
};
}
render() {
const { Component, pageProps } = this.props;
return (
<>
<Head>
<link rel="icon" href="/favicon.ico" />
</Head>
<Component {...pageProps} />
</>
);
}
}
export default MyApp;
样式/ index.scss
$foreground: #007ec5;
$background: #ebebeb;
body {
background: $background;
color: $foreground;
padding: 20px;
margin: 0;
min-height: 100vh;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句