nextjs-制作官网

news/2024/7/15 17:29:30 标签: react.js, 前端

nextjs官网

nextjs

导入本地字体

global.scss

@font-face {
  font-family: 'HYk2gj';
  src: url('/static/fonts/Montserrat-Light-6.otf');
  font-style: normal;
}

设置头部icon和标题

 <Head>
      <title>Konnect</title>
      <link rel="shortcut icon" href="/static/logo_s.png" type="image/x-icon" />
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"></meta>
    </Head>

设置移动端和pc端共存

使用了next相关的库next-useragent

一、可以使用屏幕的宽度来适配

window.innerWidth <= 1000

二、通过ua来适配

import React from 'react'
import {  withUserAgent } from 'next-useragent'
import DesktopContent from "../view/pc"
import MobileContent from "../view/h5"
import { setRem } from "../utils/rem"
// import VConsole from 'vconsole';

// const vConsole = new VConsole();

class IndexPage extends React.Component {

  static async getInitialProps(ctx) {
    return { useragent: ctx.ua.source }
  }
  componentDidMount() {
    const { ua } = this.props
    if(ua.isMobile) { 
      const { ua } = this.props
      const isMobile = ua.isMobile || ua.isIpad ||  ua.isAndroid || ua.isAndroid
      sessionStorage.setItem("isMobile", isMobile)
      setRem()
      window?.addEventListener('resize',setRem)
      return ()=>{
        window?.removeEventListener('resize',setRem)
      }
    }else {
      sessionStorage.removeItem("isMobile")
    }
  }

  render() {
    const { ua } = this.props
    const isMobile = ua.isMobile || ua.isIpad ||  ua.isAndroid || ua.isAndroid
    return (
      <>
        { isMobile ? (
        <MobileContent />
        ) : (
        <DesktopContent />
        ) }
      </>
    )
  }
}

export default withUserAgent(IndexPage)

移动端使用 postcss-px-to-viewport-8-plugin

next.config.js

module.exports = {
    plugins: {
      "postcss-px-to-viewport-8-plugin": {
        unitToConvert: "px",
        viewportWidth: 375,
        unitPrecision: 3,
        propList: ["*"],
        viewportUnit: "vw",
        fontViewportUnit: "vw",
        selectorBlackList: [],
        minPixelValue: 1,
        mediaQuery: false,
        replace: true,
        include: /\src\/h5Styles/,
        exclude: [
          /node_modules/
        ],
        landscape: false
      }
    },
  };

// module.exports = {
//   plugins: {
//     'postcss-pxtorem': {
//       rootValue: 100,
//       replace: true,
//       propList: ["*"],
//       exclude: /node_modules|^(\/src\/h5Styles\/)$|styles/i
//     }
//   }
// }

因为会作用于全局 pc的页面没有使用scss 使用style-js

next-seo 进行seo优化

https://www.npmjs.com/package/next-seo

import { NextSeo } from "next-seo";
 <NextSeo title="konnect" description="Build The Web3" />

http://www.niftyadmin.cn/n/1006016.html

相关文章

好用的网址3

智能法律咨询&#xff1a;http://www.12348.gov.cn/#/homepage Tonzhon Lite&#xff1a;http://lite.tonzhon.com/?iao.su 未知搜索&#xff1a;https://xsear.ch/ 蜜蜂去水印&#xff1a;https://video.ciding.cc/?iao.su 跑马灯&#xff1a;https://tool.retiehe.com/…

BUUCTF old-fashion 1

题目描述&#xff1a; 密文&#xff1a; Os drnuzearyuwn, y jtkjzoztzoes douwlr oj y ilzwex eq lsdexosa kn pwodw tsozj eq ufyoszlbz yrl rlufydlx pozw douwlrzlbz, ydderxosa ze y rlatfyr jnjzli; mjy gfbmw vla xy wbfnsy symmyew (mjy vrwm qrvvrf), hlbew rd symmy…

Docker镜像的知识归纳

docker镜像的知识总结归纳 一、镜像基础 1.镜像就是一个精简的操作系统 Docker镜像可以被看作是一个精简的操作系统。它包含了运行特定应用程序所需的一切&#xff0c;包括文件系统、库、依赖项和配置等。镜像是用于创建Docker容器的模板。 Docker镜像基于分层存储&#xff…

蓝桥杯专题-试题版-【打印十字图】【剪格子】【错误票据】【翻硬币】

点击跳转专栏>Unity3D特效百例点击跳转专栏>案例项目实战源码点击跳转专栏>游戏脚本-辅助自动化点击跳转专栏>Android控件全解手册点击跳转专栏>Scratch编程案例点击跳转>软考全系列点击跳转>蓝桥系列 &#x1f449;关于作者 专注于Android/Unity和各种游…

【论文】深度学习参数敏感性实验(超参数实验)实施办法

【论文】深度学习参数敏感性实验&#xff08;超参数实验&#xff09;实施办法 参数敏感性实验是什么&#xff1f;具体调整流程参考博客 参数敏感性实验是什么&#xff1f; 在深度学习技术中&#xff0c;超参数的调整十分重要&#xff01; 通过调整超参数观察训练过程中监测指标…

Zigbee模块(CC2530)详解

Zigbee模块&#xff08;CC2530&#xff09; 0. Zigbee概述1. 常见的Zigbee模块2. CC2530模块3. STM32使用CC2530模块方法代码模板 0. Zigbee概述 Zigbee是一种无线通信协议&#xff0c;专为低功耗、低数据速率的应用而设计。它工作在2.4 GHz频段&#xff0c;常用于家庭自动化、…

日历组件 el-calendar 实现标记功能

需求&#xff1a;在日历组件中选择月份时&#xff0c;可以显示当月已经质检或需质检的数据 思路&#xff1a;前端每次点击日期选择器的时候调用接口&#xff0c;接口返回当月需要质检或已质检的数据&#xff0c;前端拿到数据就开始做判断然后回显。 大体样式 代码&#xff1a…

vue3+ts-setup语法糖(props)

vue3ts-setup语法糖(props) vue3 新增了组合式api的语法糖&#xff0c;相应的props&#xff0c;也会有相应的变化。下面是我总结的三种。 <script setup lang"ts"> // 第一种&#xff1a; 使用这种方式可以设置props的 默认值 和 类型 和 是否可选 // const …