TS创建接口和接口类型数组

在app.ts中引用

import { users, IRoute, IUser, routes } from "./data";

在index.ts中统一导入后导出

export * from "./routes";
export * from "./users";

import routes from "./routes";
import users from "./users";

export { routes, users };

在users 和routes中创建并导出接口和接口类型的数组

export interface IUser {
  id: number;
  username: string;
  auth: number[];
}

const users: IUser[] = [
  {
    id: 1,
    username: "zhangsan",
    auth: [2, 3, 6, 7],
  },
  {
    id: 2,
    username: "lisi",
    auth: [2, 3, 5, 6, 7, 8],
  },
  {
    id: 3,
    username: "wangwu",
    auth: [2, 3, 4, 5, 6, 7, 8],
  },
];

export default users;
export interface IRoute {
  id: number;
  pid: number;
  path: string;
  name: string;
  link?: string;
  title: string;
}

const routes: IRoute[] = [
  {
    id: 2,
    pid: 0,
    path: "/course",
    name: "Course",
    title: "课程管理",
  },
  {
    id: 3,
    pid: 2,
    path: "operate",
    name: "CourseOperate",
    link: "/course/operate",
    title: "课程操作",
  },
  {
    id: 4,
    pid: 3,
    path: "info_data",
    name: "CourseInfoData",
    link: "/course/operate/info_data",
    title: "课程数据",
  },
  {
    id: 5,
    pid: 2,
    path: "add",
    name: "CourseAdd",
    link: "/course/add",
    title: "增加课程",
  },
  {
    id: 6,
    pid: 0,
    path: "/student",
    name: "Student",
    title: "学生管理",
  },
  {
    id: 7,
    pid: 6,
    path: "/student/operate",
    name: "StudentOperate",
    link: "/student/operate",
    title: "学生操作",
  },
  {
    id: 8,
    pid: 6,
    path: "add",
    name: "StudentAdd",
    link: "/student/add",
    title: "增加学生",
  },
];

export default routes;
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值