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

react_15

动态菜单

图标要独立安装依赖

npm install @ant-design/icons

图标组件,用来将字符串图标转换为标签图标

import * as icons from "@ant-design/icons";
interface Module {[p: string]: any;
}
const all: Module = icons;
export default function Icon({ name }: { name: string }) {const Icon = all[name];return <Icon></Icon>;
}

登录页面

import { Button, Form, Input, message } from "antd";
import RoutesStore from "../store/RoutesStore";
import { LoginReq } from "../model/Student";
import { observer } from "mobx-react-lite";
import { useNavigate } from "react-router-dom";
import { useEffect } from "react";function A8Login() {function onFinish(values: LoginReq) {RoutesStore.login(values);}const nav = useNavigate();useEffect(() => {if (RoutesStore.state === "success") {//登陆成功,跳转到主页nav("/");} else if (RoutesStore.state === "error") {//登录失败message.error(RoutesStore.message);}}, [RoutesStore.state]);return (<div style={{ paddingTop: 200 }}><Formname="basic"labelCol={{ span: 8 }}wrapperCol={{ span: 8 }}onFinish={onFinish}><Form.Itemlabel="用户名"name="username"rules={[{ required: true, message: "用户名必须" }]}><Input autoComplete="off" /></Form.Item><Form.Itemlabel="密码"name="password"rules={[{ required: true, message: "密码必须" }]}><Input.Password autoComplete="off" /></Form.Item><Form.Item wrapperCol={{ offset: 8, span: 6 }}><Button type="primary" htmlType="submit">登录</Button></Form.Item></Form></div>);
}
export default observer(A8Login);
  • 用 useNavigate() 返回的函数跳转的代码不能包含在函数式组件的主逻辑中,只能放在

    • 其它事件处理函数中

    • 写在副作用函数 useEffect 之中

http://www.lryc.cn/news/218544.html

相关文章:

  • 关于ROS的网络通讯方式TCP/UDP
  • Leetcode—421.数组中两个数的最大异或值【中等】明天写一下字典树做法!!!
  • 数智赋能!麒麟信安参展全球智慧城市大会
  • 基础课21——知识库管理
  • 网络运维Day01
  • 从零配置一台linux主机
  • 【蓝桥每日一题]-倍增(保姆级教程 篇1)
  • CNN(卷积神经网络)、RNN(循环神经网络)和GCN(图卷积神经网络)
  • 在markdown中怎么画表格
  • 每天五分钟计算机视觉:搭建手写字体识别的卷积神经网络
  • 【React】【react-globe.gl】3D Objects效果
  • 目标检测YOLO系列从入门到精通技术详解100篇-【目标检测】SLAM(补充篇)
  • Pytorch 缓解过拟合和网络退化
  • 【算法】昂贵的聘礼(dijkstra算法)
  • hackergame2023菜菜WP
  • ubuntu20.04.6使用FTP-及相关安全配置
  • C++中不允许复制的类
  • 使用Python 脚自动化操作服务器配置
  • DL Homework 6
  • 软考高项论文-绩效域
  • 设计模式之装饰模式--优雅的增强
  • 前端vue,后端springboot。如何防止未登录的用户直接浏览器输入地址访问
  • linux安装Chrome跑web自动化
  • linux环境下编译,安卓平台使用的luajit库
  • indexedDB笔记
  • 系统提示缺少或找不到emp.dll文件的详细解决方案
  • Python实现自动化网页操作
  • 03 矩阵与线性变换
  • MySQL InnoDB数据存储结构
  • 【数据结构】数组和字符串(十五):字符串匹配2:KMP算法(Knuth-Morris-Pratt)