【穀粒學院】017-前端框架開發過程介紹、新增講師模組
目錄
4、在api資料夾下建立teacher.js檔案,封裝資料請求
一、前端框架開發過程介紹
1、框架使用過程
第一步:新增路由
第二步:點選某個路由,顯示對應頁面
第三步:在頁面中新增內容
編寫內容和請求資料的邏輯,其中請求資料進行了封裝:
所封裝的內容:
二、新增講師模組
1、在路由src\router\index.js中新增路由
import Vue from 'vue'// vue
import Router from 'vue-router'// 路由
Vue.use(Router)
/* Layout */
import Layout from '@/layout'
/**
* Note: sub-menu only appear when route children.length >= 1
* Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
*
* hidden: true if set true, item will not show in the sidebar(default is false)
* alwaysShow: true if set true, will always show the root menu
* if not set alwaysShow, when item has more than one children route,
* it will becomes nested mode, otherwise not show the root menu
* redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
* name:'router-name' the name is used by <keep-alive> (must set!!!)
* meta : {
roles: ['admin','editor'] control the page roles (you can set multiple roles)
title: 'title' the name show in sidebar and breadcrumb (recommend set)
icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
}
*/
/**
* constantRoutes
* a base page that does not have permission requirements
* all roles can be accessed
*/
/**
* 匯出模組開始
*/
/**
* 路由:
* 這裡的路由分為兩種,constantRoutes 和 asyncRoutes:
* 1、constantRoutes: 代表那些不需要動態判斷許可權的路由,如登入頁、404、等通用頁面;
* 2、asyncRoutes: 代表那些需求動態判斷許可權並通過 addRoutes 動態新增的頁面;
*/
export const constantRoutes = [// 不需要動態判斷許可權的路由
{
path: '/login', // 登入
component: () => import('@/views/login/index'),
hidden: true
},
{
path: '/404', // 404
component: () => import('@/views/404'),
hidden: true
},
/**
* 首頁
*/
{
path: '/', // 首頁
component: Layout,
redirect: '/dashboard', // 重定向
children: [{ // 子地址
path: 'dashboard', // 路徑
name: 'Dashboard', // 名字
component: () => import('@/views/dashboard/index'),
meta: { title: '首頁', icon: 'dashboard' }
}]
},
/**
* 講師管理模組
*/
{
path: '/teacher', // 路徑
component: Layout,
redirect: '/teacher/add', // 重定向到/example/table
name: '講師管理',
meta: { title: '講師管理', icon: 'el-icon-s-help' }, // 名字和圖示
children: [
{
path: 'add', // 路徑是 /example/table
name: '新增講師', // 名字
component: () => import('@/views/teacher/add'), // 指向
meta: { title: '新增講師', icon: 'table' } // 基本資訊:名字和圖示
},
{
path: 'list',
name: '講師列表',
component: () => import('@/views/teacher/list'),
meta: { title: '講師列表', icon: 'tree' }
}
]
},
/**
* Example
*/
{
path: '/example', // 路徑
component: Layout,
redirect: '/example/table', // 重定向到/example/table
name: 'Example',
meta: { title: 'Example', icon: 'el-icon-s-help' }, // 名字和圖示
children: [
{
path: 'table', // 路徑是 /example/table
name: 'Table', // 名字
component: () => import('@/views/table/index'), // 指向
meta: { title: 'Table', icon: 'table' } // 基本資訊:名字和圖示
},
{
path: 'tree',
name: 'Tree',
component: () => import('@/views/tree/index'),
meta: { title: 'Tree', icon: 'tree' }
}
]
},
/**
* Form
*/
{
path: '/form',
component: Layout,
children: [
{
path: 'index',
name: 'Form',
component: () => import('@/views/form/index'),
meta: { title: 'Form', icon: 'form' }
}
]
},
/**
* Nested
*/
{
path: '/nested',
component: Layout,
redirect: '/nested/menu1',
name: 'Nested',
meta: {
title: 'Nested',
icon: 'nested'
},
children: [
{
path: 'menu1',
component: () => import('@/views/nested/menu1/index'), // Parent router-view
name: 'Menu1',
meta: { title: 'Menu1' },
children: [
{
path: 'menu1-1',
component: () => import('@/views/nested/menu1/menu1-1'),
name: 'Menu1-1',
meta: { title: 'Menu1-1' }
},
{
path: 'menu1-2',
component: () => import('@/views/nested/menu1/menu1-2'),
name: 'Menu1-2',
meta: { title: 'Menu1-2' },
children: [
{
path: 'menu1-2-1',
component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
name: 'Menu1-2-1',
meta: { title: 'Menu1-2-1' }
},
{
path: 'menu1-2-2',
component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
name: 'Menu1-2-2',
meta: { title: 'Menu1-2-2' }
}
]
},
{
path: 'menu1-3',
component: () => import('@/views/nested/menu1/menu1-3'),
name: 'Menu1-3',
meta: { title: 'Menu1-3' }
}
]
},
{
path: 'menu2',
component: () => import('@/views/nested/menu2/index'),
name: 'Menu2',
meta: { title: 'menu2' }
}
]
},
/**
* External Link
*/
{
path: 'external-link',
component: Layout,
children: [
{
path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
meta: { title: 'External Link', icon: 'link' }
}
]
},
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true }
]
/**
* 匯出模組結束
*/
/**
* 路由
*/
const createRouter = () => new Router({
// mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
/**
* 路由
*/
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
/**
* 匯出:重置路由
*/
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher // reset router
}
/**
* 匯出:路由
*/
export default router
2、新增對應vue頁面
圖示:
程式碼示例:
<template>
<div>
新增講師
</div>
</template>
<script>
</script>
<style>
</style>
3、講師模組最終效果展示
4、在api資料夾下建立teacher.js檔案,封裝資料請求
(仿照table.js寫)
import request from '@/utils/request'
export function getList() {
return request({
url: '/edu-admin/teacher/list', // 路徑
method: 'get'
});
}
5、前端拿取
到這裡,我發現已經有很多內容跟視訊裡面不一樣了,接下來,我打算做重點筆記,不再一步一步做完整筆記了。
相關文章
- 用 Composer 組建了個 PHP 框架
- 編寫 Netty / RPC 客戶端【框架程式碼分析】
- 大資料常用處理框架
- 乾貨預警,一篇文章帶你徹底搞懂 Laravel 框架的執行原理!!!
- VS2019/MFC程式設計入門之(如何利用MFC嚮導生成單文件應用程式框架)
- Java 持久層框架之 MyBatis
- Angular實戰之使用NG-ZORRO建立一個企業級中後臺框架(新手入門篇)
- Erlang那些事兒第2回之我是模組(module),一檔案一模組
- 3- C語言編譯過程
- Spring框架增強-全域性異常處理機制-根據目錄結構自動生成路由字首-引數效驗機制以及自定義效驗
- 一些非常好用的 Laravel 框架擴充套件包你知道麼?
- odoo開發:關於列印repair模組PDF報表,預設紙張頭部有一大塊空白無法修改的問題解決方案
- 關於使用 Appium 的 wda 測試 IOS 的 XCUI 框架 app 中元素的問題
- .NET框架介紹
- 446、Java框架100 -【MyBatis - if】 2020.12.23
- 關於typedef和struct使用過程中的一些思考(2020/12/23更新)
- 閉關修煉180天--手寫持久層框架(mybatis簡易版)
- SSM框架整合開發
- 天天生鮮專案需求分析——基於Django框架的天天生鮮電商網站專案系列部落格(一)