当前位置: 首页 > news >正文

四十八----react实战

一、项目中css模块化管理

1、css-loader
以下可以使用styles.xxx方式使用class是因为使用css-loader配置了module。

import styles from './index.less'
export const App(){return <div className={styles.xxx}>hello word</div>
}//webpack配置
{test:/\.css$/,use[{loader:'css-loader',options:{modules:{localIndentName:isDevelopment?"[path]_[name]_[local]":"[hash:base64:5]"}}}]
}

开发环境使用路径模块名类名命名方便调试"[path][name][local]“,生产环境使用”[hash:base64:5]"这个命名进行压缩混淆代码减少代码体积。
2、css in js

import styles from './styles.js'
export const App(){return <div style={styles.xxx}>jeelo</div>
}//.styles.js
const xxx = {backgroundColor:'red'
}

3、styled-components

import styled from 'styled-components'
const Button = styled.button`background:#ff0`
export const App(){return <Button >jeelo</Button>
}

tailwind css是原子化的css包,解决一些css的复杂性,类名约定的负担。它主要使用postcss进行css的babelloader转换编译。
控制粒度:bootsrap>tailwind>css
headless ui 是没有样式的。

二、实战一个知乎首页

app.js

import { BrowserRouter, Routes, Route } from "react-router-dom";
// pages
import Home from './pages/home'
import CommandList from "./pages/home/tabPages/commandList";export default function App(params) {return <BrowserRouter><Routes><Route path="/" element={<Home />}><Route path="" element={<CommandList />} /><Route path="follow" element={<div>Follow</div>} /><Route path="hot" element={<div>Hot</div>} /><Route path="zvideo" element={<div>ZVideo</div>} /></Route><Route path="/xen" element={<div>Xen</div>}></Route><Route path="/explore" element={<div>Explore</div>}></Route><Route path="/question" element={<div>Question</div>}></Route></Routes></BrowserRouter>
};

home.js
这里的navigator导航顶部栏为了滑动滚动条,导航栏依旧留在顶部使用了position:sticky属性,维护一个hide属性在传递给naviagtor组件

// import { Outlet } from "react-router-dom";
import { useState } from 'react';
// components
import Navigation from "../../components/navigation";
import Card from '../../components/card';
// pages
import TabPages from './tabPages';
import Creation from './siderPages/creation';
import AdvancedBtns from './siderPages/advancedBtns';
import SelfFuncs from './siderPages/selfFuncs';export default function Home(params) {const [hide, setHide] = useState(true);const handleChange = (isHide) => setHide(isHide);return <div><Navigation className="sticky top-0" hide={hide} /><div className="mx-auto max-w-7xl w-320 flex m-2"><Card className="w-2/3"><TabPages onChange={handleChange} /></Card><div className="w-1/3"><Card><Creation /></Card><Card><AdvancedBtns /></Card><Card><SelfFuncs /></Card></div></div></div>
};

navigation导航栏,navigator栏根据滚动传递的hide属性显示不同的顶部栏

import React from 'react'
import { Fragment } from 'react';
import { NavLink } from 'react-router-dom';
import { Menu, Transition } from '@headlessui/react';
import { BellIcon } from '@heroicons/react/outline';const navs = [{ name: "首页", to: "/" },{ name: "会员", to: "/xen" },{ name: "发现", to: "/explore" },{ name: "等你来答", to: "/question" },
]const tabs = [{ name: "关注", to: "/follow" },{ name: "推荐", to: "/" },{ name: "热榜", to: "/hot" },{ name: "视频", to: "/zvideo" },
]const Logo = () => <div className='flex'><div className=' flex-shrink-0 flex items-center'><svg viewBox="0 0 64 30" fill="#0066FF" width="64" height="30" className="css-1hlrcxk"><path d="M29.05 4.582H16.733V25.94h3.018l.403 2.572 4.081-2.572h4.815V4.582zm-5.207 18.69l-2.396 1.509-.235-1.508h-1.724V7.233h6.78v16.04h-2.425zM14.46 14.191H9.982c0-.471.033-.954.039-1.458v-5.5h5.106V5.935a1.352 1.352 0 0 0-.404-.957 1.378 1.378 0 0 0-.968-.396H5.783c.028-.088.056-.177.084-.255.274-.82 1.153-3.326 1.153-3.326a4.262 4.262 0 0 0-2.413.698c-.57.4-.912.682-1.371 1.946-.532 1.453-.997 2.856-1.31 3.693C1.444 8.674.28 11.025.28 11.025a5.85 5.85 0 0 0 2.52-.61c1.119-.593 1.679-1.502 2.054-2.883l.09-.3h2.334v5.5c0 .5-.045.982-.073 1.46h-4.12c-.71 0-1.39.278-1.893.775a2.638 2.638 0 0 0-.783 1.874h6.527a17.717 17.717 0 0 1-.778 3.649 16.796 16.796 0 0 1-3.012 5.273A33.104 33.104 0 0 1 0 28.74s3.13 1.175 5.425-.954c1.388-1.292 2.631-3.814 3.23-5.727a28.09 28.09 0 0 0 1.12-5.229h5.967v-1.37a1.254 1.254 0 0 0-.373-.899 1.279 1.279 0 0 0-.909-.37z"></path><path d="M11.27 19.675l-2.312 1.491 5.038 7.458a6.905 6.905 0 0 0 .672-2.218 3.15 3.15 0 0 0-.28-2.168l-3.118-4.563zM51.449 15.195V5.842c4.181-.205 7.988-.405 9.438-.483l.851-.05c.387-.399.885-2.395.689-3.021-.073-.25-.213-.666-.638-.555a33.279 33.279 0 0 1-4.277.727c-2.766.321-3.97.404-7.804.682-6.718.487-12.709.72-12.709.72a2.518 2.518 0 0 0 .788 1.834 2.567 2.567 0 0 0 1.883.706c2.278-.095 5.598-.25 8.996-.41v9.203h-12.78c0 .703.281 1.377.783 1.874a2.69 2.69 0 0 0 1.892.777h10.105v7.075c0 .887-.464 1.192-1.231 1.214h-3.92a4.15 4.15 0 0 0 .837 1.544 4.2 4.2 0 0 0 1.403 1.067 6.215 6.215 0 0 0 2.71.277c1.36-.066 2.967-.826 2.967-3.57v-7.607h11.28c.342 0 .67-.135.91-.374.242-.239.378-.563.378-.902v-1.375H51.449z"></path><path d="M42.614 8.873a2.304 2.304 0 0 0-1.508-.926 2.334 2.334 0 0 0-1.727.405l-.376.2

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • IO进程线程 day1 IO基础+标准IO
  • 爬虫工作量由小到大的思维转变---<第三十章 Scrapy Redis 第一步(配置同步redis)>
  • UntiyShader(六)Unity提供的Cg/HLSL语义
  • AI提示词入门教程
  • idea中终端Terminal页面输入命令git log后如何退出
  • 第一章 简单编程实现花生壳的ddns功能
  • Redis7.2.3(Windows版本)
  • English: go through customs
  • vue3为什么使用带有 .value 的 ref,而不是普通的变量
  • Pytorch的讲解及实战·MNIST数据集手写数字识别
  • Android 8.1 设置USB传输文件模式(MTP)
  • gitee+picgo+typora图床搭建
  • 小秋SLAM入门实战深度学习所有文章汇总
  • go 语言程序设计第1章--入门
  • nginx安装和配置
  • 时间复杂度分析经典问题——最大子序列和
  • (三)从jvm层面了解线程的启动和停止
  • 【笔记】你不知道的JS读书笔记——Promise
  • angular2 简述
  • download使用浅析
  • HTTP那些事
  • JS数组方法汇总
  • js中forEach回调同异步问题
  • MYSQL如何对数据进行自动化升级--以如果某数据表存在并且某字段不存在时则执行更新操作为例...
  • PHP那些事儿
  • 从地狱到天堂,Node 回调向 async/await 转变
  • 关于springcloud Gateway中的限流
  • 今年的LC3大会没了?
  • 面试总结JavaScript篇
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • 微信端页面使用-webkit-box和绝对定位时,元素上移的问题
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 写代码的正确姿势
  • 正则表达式-基础知识Review
  • (八十八)VFL语言初步 - 实现布局
  • (附源码)springboot人体健康检测微信小程序 毕业设计 012142
  • (使用vite搭建vue3项目(vite + vue3 + vue router + pinia + element plus))
  • (推荐)叮当——中文语音对话机器人
  • (转载)虚幻引擎3--【UnrealScript教程】章节一:20.location和rotation
  • .NET 8.0 中有哪些新的变化?
  • .NET Framework Client Profile - a Subset of the .NET Framework Redistribution
  • .NET Standard 支持的 .NET Framework 和 .NET Core
  • .Net 执行Linux下多行shell命令方法
  • ?.的用法
  • [ A*实现 ] C++,矩阵地图
  • []FET-430SIM508 研究日志 11.3.31
  • [<MySQL优化总结>]
  • [20150904]exp slow.txt
  • [acm算法学习] 后缀数组SA
  • [APIO2012] 派遣 dispatching
  • [C#]手把手教你打造Socket的TCP通讯连接(一)
  • [C++]priority_queue的介绍及模拟实现
  • [Day 63] 區塊鏈與人工智能的聯動應用:理論、技術與實踐
  • [Git][分支管理][上]详细讲解
  • [GYCTF2020]Ez_Express