vue2+若依框架plus交互 路由介紹

本周及寒假

參加了校企合作的工程過程管理,和學長學姐一起寫項目,之前學了vue也沒有應用,然后對框架很多組件的用法不太了解,前期耽誤了一些時間。

框架模塊

首先是框架模塊的介紹 api存了一些系統管理及發送請求的方法
在這里插入圖片描述
例如project.js

import request from '@/utils/request'
import { getToken } from '@/utils/auth'
//添加新的公司
let token = getToken();
export function getTypeOnline(compName, compType) {return request({url: `/project/queryCompany?name=${compName}&type=${compType}`,headers: {isToken: true,token: `Bearer ${token}`},method: 'post',})
}

然后是asset文件夾 存了文件的靜態資源
在這里插入圖片描述
component存的是用到的組件 layout也是組件 可以將頁面的組件拆分展示成多個
plugins仿制的是插件進行鑒權等等,router是路由配置文件 store放置的是拆分出來的vuex里面的分模塊化的內容

在這里插入圖片描述

路由配置

菜單配置路由

若依框架可以通過菜單進行路由配置 進入系統管理的菜單管理
在這里插入圖片描述
通過改變菜單的目錄和菜單進行配置 輸入組件路徑和路由地址 既可以在左邊側邊欄渲染出導航欄
在這里插入圖片描述

路由配置

這是我配置的路由 因為本來在菜單設置的三級路由一直報錯 這個配置的路由可以通過
meta: { title: ‘首頁’}渲染你面包屑

 {path: '',component: Layout,redirect: 'homePage',meta: { title: '首頁', icon: 'dashboard', affix: true },children: [{path: 'homePage',component: () => import('@/views/home/homePage'),name: 'homePage',meta: { title: '公司庫', icon: 'dashboard', affix: true },children:[]},{path: 'project',component: () => import('@/views/home/projectManeger'),name: 'Project',meta: { title: '工程管理', icon: 'dashboard', affix: true },children: [{path: 'projectMain/:param',props: true,component: () => import('@/views/home/projectMain'),name: 'projectMain',hidden: true,meta: { title: '工程詳情', icon: 'dashboard', affix: true, }}],},]},

登錄邏輯

若依的登錄邏輯是寫好了的 在login.vue我們可以看到如下代碼

 handleLogin() {this.$refs.loginForm.validate(valid => {if (valid) {this.loading = true;if (this.loginForm.rememberMe) {Cookies.set("username", this.loginForm.username, { expires: 30 });Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });} else {Cookies.remove("username");Cookies.remove("password");Cookies.remove('rememberMe');}this.$store.dispatch("Login", this.loginForm).then(() => {this.$router.push({ path: '/home/homePage' || "/" }).catch(()=>{});}).catch(() => {this.loading = false;if (this.captchaEnabled) {this.getCode();}});}});}

可以看出登錄調用的是vuex里面的內容 可以在store->modules->user.js里面控制
在action可以看到

Login({ commit }, userInfo) {const username = userInfo.username.trim()const password = userInfo.passwordconst code = userInfo.codeconst uuid = userInfo.uuidreturn new Promise((resolve, reject) => {login(username, password, code, uuid).then(res => {setToken(res.data.token)commit('SET_TOKEN', res.data.token)resolve()}).catch(error => {reject(error)})})},

發送請求的login方法在src/api/login.js中
這個request是若依封裝的攔截器

import request from '@/utils/request'// 登錄方法
export function login(username, password, code, uuid) {const data = {username,password,code,uuid}return request({url: '/login',headers: {isToken: false},method: 'post',data: data})
}

存儲token的部分 在src/utils/auth.js中

import Cookies from 'js-cookie'const TokenKey = 'Admin-Token'export function getToken() {return Cookies.get(TokenKey)
}export function setToken(token) {return Cookies.set(TokenKey, token)
}export function removeToken() {return Cookies.remove(TokenKey)
}

交互

寫的是分頁 點擊刪除之后更新 所以把數據以及頁數存儲到了vuex中

<template><div class="componnentMain"><div class="addNewCom"><button @click="addNewomponent('add-newCoponent')" id="addnewBtn">新增</button><el-dialog :title="dialogComtitle" :visible.sync="addDialogCom"><template v-if="currentComponent == 'add-newCoponent'"><add-newCoponent :addDialogCom.sync="addDialogCom" /></template><template v-else><edit-comVue:addDialogCom.sync="addDialogCom":listData="ownlistData"/></template></el-dialog></div><el-table :data="dataList" style="width: 97%" class="comLable"><el-table-column prop="compName" label="公司名稱" width="260"></el-table-column><el-table-column prop="createTime" label="創建時間" width="195"><template slot-scope="{ row }">{{ turnshowTime(row.createTime) }}</template></el-table-column><el-table-column prop="compType" label="公司類別" width="190"></el-table-column><el-table-column prop="compInvite" label="注冊邀請碼" width="330"><template slot-scope="{ row }"><span class="address-container">{{ row.compInvite }}</span><!-- img 放在 span 之后 --><imgclass="copyVisit"src="@/assets/images/copy.png"alt=""srcset=""/></template></el-table-column><el-table-column label="操作" width="241" fixed="right"><template slot-scope="{ row }"><span class="combtn" @click="editcomponent('edit - comVue', row)">詳情</span><span class="combtn" @click="editcomponent('edit - comVue', row)">編輯</span><span class="deleteCom" @click="delteCompany(row.id)"> 刪除 </span></template></el-table-column></el-table><div class="pageComChange"><div class="pageComChangeCenter"><el-paginationbackgroundlayout="prev, pager,next":page-count="Number(totalPages)":current-page="currentPage"@current-change="handleCurrentChange"></el-pagination></div></div></div>
</template>
import { mapState, mapMutations, mapActions } from "vuex";
//先引入vuex模塊
export default {components: {"add-newCoponent": addnewComVue,"edit-comVue": editComVue,},computed: {...mapState("companyPage", ["pageSize","totalPages","dataList","searchConten",]),},currentPage: {get() {return this.currentPage;},set(val) {this.handleCurrentChange(val);},},mounted() {this.fetchData();//在掛載調用一次分頁接口},methods: {addNewomponent(componentType) {this.currentComponent = componentType;this.addDialogCom = !this.addDialogCom;this.dialogComtitle = "新建公司";},editcomponent(componentType, rowData) {this.currentComponent = componentType;this.addDialogCom = !this.addDialogCom;this.dialogComtitle = "修改公司信息";this.ownlistData = rowData;},...mapMutations("companyPage", ["searchCompanysendMethos","updatePagination",]),...mapActions("companyPage", ["serachComoanyactions", "fetchData"]),handleCurrentChange(val) {this.currentPage = val;if (this.searchConten == "" || this.searchType == "") {this.updatePagination({currentPage: val,pageSize: this.pageSize,});this.fetchData();} else {this.searchCompanysendMethos({currentPage: 1,pageSize: this.pageSize,searchConten: this.searchComvalue,searchType: this.searchType,});this.serachComoanyactions();}},delteCompany(id) {this.$confirm("確定要刪除該公司嗎?", "提示", {confirmButtonText: "確定",cancelButtonText: "取消",type: "warning",}).then(() => {const comids = [id];deleteCompany(comids).then((data) => {if (data.code == 200) {this.$message.success('刪除公司成功')//這是判斷有沒有搜索內容if (this.searchConten == "" || this.searchType == "") {this.updatePagination({currentPage:this.currentPage,pageSize: this.pageSize,});this.fetchData();} else {this.searchCompanysendMethos({currentPage: 1,pageSize: this.pageSize,searchConten: this.searchComvalue,searchType: this.searchType,});this.serachComoanyactions();}} else {this.$message.error("刪除該公司失敗");}});}).catch((error) => {console.log(error);});},turnshowTime(timestamp) {// 使用導入的時間轉換方法return turnshowTime(timestamp);},},data() {return {currentComponent: "",dialogComtitle: "",addDialogCom: false,currentPage: 1,ownlistData: {},};},
};

首先先注冊模塊

//store/index.vue
const store = new Vuex.Store({modules: {app,dict,user,tagsView,permission,settings,companyPage,projectPage},getters
})

模塊里面的命名空間要設置為true 并進行傳遞數據的更新

import { getAllCompany,getSearchCompany} from "../../api/company";
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const companyPage=({namespaced: true,state: {currentPage: 1,pageSize: 10,totalPages: 0,searchConten:'',searchType:"",dataList: [] // 存儲數據列表},mutations: {updatePagination(state, payload) {state.currentPage = payload.currentPage;state.pageSize = payload.pageSize;state.totalPages = payload.totalPages;},updateDataList(state, dataList) {state.dataList = dataList;},searchCompanysendMethos(state, payload) {state.currentPage = payload.currentPage;state.pageSize = payload.pageSize;state.totalPages = payload.totalPages;state.searchType=payload.searchType,state.searchConten=payload.searchConten},updateSearchList(state, dataList) {state.dataList = dataList;}},actions: {async fetchData({ commit, state }) {try {// 調用接口獲取公司數據const response = await getAllCompany(state.pageSize,state.currentPage);// 更新分頁狀態commit('updatePagination', {currentPage: state.currentPage,pageSize: state.pageSize,totalPages: response.pages,dataList:response.records,});// 更新數據列表commit('updateDataList', response.records);} catch (error) {console.error('Error fetching company data:', error);}},async serachComoanyactions ({ commit, state }) {try {// 調用接口獲取公司數據const response = await getSearchCompany(state.pageSize,state.currentPage,state.searchConten,state.searchType);commit('searchCompanysendMethos', {currentPage: state.currentPage,pageSize: state.pageSize,totalPages: response.pages,dataList:response.records,});// 更新數據列表commit('updateDataList', response.records);} catch (error) {console.error('Error fetching company data:', error);}}
}
});
export default companyPage

總結

vue寫項目比之前用原生js寫項目代碼量要少得多 同時 框架好用是好用 但是要了解他的項目架構以及自帶的一些方法

下周計劃

先完成項目 然后學習一下ts 寒假沒完全學完

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/716079.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/716079.shtml
英文地址,請注明出處:http://en.pswp.cn/news/716079.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【python】`assert`斷言語句

assert是一個斷言語句&#xff0c;用于在代碼中檢查某個條件是否為真。 如果條件為假&#xff0c;將觸發AssertionError 異常&#xff0c;從而指示存在錯誤。

Linux獲取進程(系統啟動時間和運行時間)運行時間

Linux獲取進程運行時間 思路&#xff1a;使用 ps - o命令 ps -p 986 -o etime可以獲取進程986的執行時間&#xff0c;不論系統時間有沒有發生改變&#xff0c;它都可以返回正確的結果: 總結&#xff1a;etime 是真正的程序運行時間&#xff0c;而不是系統運行時間與進程啟動…

在您的下一個項目中選擇 Golang 和 Node.js 之間的抉擇

作為一名軟件開發者&#xff0c;我總是在尋找構建應用程序的最快、最高效的工具。在速度和處理復雜任務方面&#xff0c;我認為 Golang 和 Node.js 是頂尖技術。兩者在性能方面都享有極高的聲譽。但哪一個更快——Golang 還是 Node&#xff1f;我決定深入一些硬核基準測試&…

java-ssm-jsp-寵物護理預定系統

java-ssm-jsp-寵物護理預定系統 獲取源碼——》公主號&#xff1a;計算機專業畢設大全

ASPICE實操中的那點事兒-底層軟件的單元測試該如何做

先來說下ASPICE項目實操中遇到的問題&#xff1a; 底層軟件在做單元測試時&#xff0c;從ASPICE角度看&#xff0c;該如何做&#xff1f;要不要在目標控制器或開發板中去測&#xff1f;尤其是復雜驅動&#xff0c;如果不在將程序下載到硬件中&#xff0c;該如何測試&#xff1…

物聯網與智慧城市:融合創新,塑造未來城市生活新圖景

一、引言 在科技飛速發展的今天&#xff0c;物聯網與智慧城市的融合創新已成為推動城市發展的重要力量。物聯網技術通過連接萬物&#xff0c;實現信息的智能感知、傳輸和處理&#xff0c;為智慧城市的構建提供了無限可能。智慧城市則運用物聯網等先進技術&#xff0c;實現城市…

使用R語言進行Logistic回歸分析(2)

一、數據集描述&#xff0c;問題要求 下表是40位肺癌病人的生存資料&#xff0c;X1表示生活行為能力平分&#xff08;1到100&#xff09;&#xff0c;X2為病人的年齡&#xff08;年&#xff09;&#xff0c;X3由診斷到進入研究的時間&#xff08;月&#xff09;&#xff0c;X4…

291.【華為OD機試】模擬目錄管理(JavaPythonC++JS實現)

??點擊這里可直接跳轉到本專欄,可查閱頂置最新的華為OD機試寶典~ 本專欄所有題目均包含優質解題思路,高質量解題代碼(Java&Python&C++&JS分別實現),詳細代碼講解,助你深入學習,深度掌握! 文章目錄 一. 題目-模擬目錄管理二.解題思路三.題解代碼Python題解…

計算機設計大賽 深度學習火車票識別系統

文章目錄 0 前言1 課題意義課題難點&#xff1a; 2 實現方法2.1 圖像預處理2.2 字符分割2.3 字符識別部分實現代碼 3 實現效果4 最后 0 前言 &#x1f525; 優質競賽項目系列&#xff0c;今天要分享的是 &#x1f6a9; 圖像識別 火車票識別系統 該項目較為新穎&#xff0c;適…

Pycharm的下載安裝與漢化

一.下載安裝包 1.接下來按照步驟來就行 2.然后就能在桌面上找到打開了 3.先建立一個文件夾 二.Pycharm的漢化

ABAP - SALV教程07 斑馬紋顯示和SALV標題

SALV設置斑馬紋和標題 METHOD set_layout.DATA: lo_display TYPE REF TO cl_salv_display_settings. * 取得顯示對象lo_display co_alv->get_display_settings( ).* 設置ZEBRA顯示lo_display->set_striped_pattern( X ). * 設置Titlelo_display->set_list_he…

企業微信變更主體怎么改?

企業微信變更主體有什么作用&#xff1f;做過企業運營的小伙伴都知道&#xff0c;很多時候經常會遇到現有的企業需要注銷&#xff0c;切換成新的企業進行經營的情況&#xff0c;但是原來企業申請的企業微信上面卻積累了很多客戶&#xff0c;肯定不能直接丟棄&#xff0c;所以這…

【二】【SQL】去重表數據及分組聚合查詢

去重表數據 表的準備工作 去除表中重復的數據&#xff0c;重復的數據只留一份。 mysql> create table duplicate_table (-> id int,-> name varchar(20)-> ); Query OK, 0 rows affected (0.03 sec)mysql> insert into duplicate_table values-> (100,aaa)…

Day24-yum與rpm軟件包管理2

Day24-yum與rpm軟件包管理2 1. 配置緩存rpm包2. 為什么要緩存&#xff1f;3. 組包相關指令4. yum幫助與補全功能4.1 補全4.2 什么是yum源4.3 常見互聯網 yum 源 5. 搭建局域網YUM倉庫實踐 1. 配置緩存rpm包 修改yum.conf配置 [rootoldboy ~]# sed -i.bak s#keepcache0#keepca…

SLAM基礎知識:前端和后端

在基于濾波的SLAM算法中&#xff0c;使用迭代卡爾曼濾波&#xff08;Iterative Kalman Filtering&#xff09;來求解當前幀狀態量的步驟通常屬于SLAM系統的前端部分。 前端負責處理傳感器數據&#xff0c;進行狀態估計和地圖構建的初步步驟。迭代卡爾曼濾波作為一種濾波器&…

批次大小對ES寫入性能影響初探

問題背景 ES使用bulk寫入時每批次的大小對性能有什么影響&#xff1f;設置每批次多大為好&#xff1f; 一般來說&#xff0c;在Elasticsearch中&#xff0c;使用bulk API進行批量寫入時&#xff0c;每批次的大小對性能有著顯著的影響。具體來說&#xff0c;當批量請求的大小增…

PVLAN組網實驗

一&#xff0c;PVLAN類型 主VLAN 主VLAN可以由多個輔助私用VLAN組成&#xff0c;而這些輔VLAN與主VLAN屬于同一子網。 輔助VLAN ① 團體VLAN&#xff1a;如果某個端口屬于團體VLAN&#xff0c;那么它就不僅能夠與相同團體VLAN中的其他端口進行通信&#xff0c;而且還能夠與…

使用rsync同步服務器和客戶端的文件夾

使用rsync同步服務器和客戶端的文件夾 實現目的實驗準備實驗操作步驟服務器操作關閉防火墻和SELINUX安裝rsync修改服務器配置文件/etc/rsync.conf創建服務器備份文件的目錄創建rsync系統運行的用戶修改備份文件的所有者和所屬組創建rsync.passwd啟動rsync服務并進行驗證 客戶端…

中間件安全(概述)有中間件的各類鏈接和官網信息和漏洞庫以及配置問題和開源工具

分類主要包括Apache、IIS、Tomcat、weblogic、websphere、Jboss等相關的技術知識和實踐。 以Apache為例講一講如何保證中間件安全 中間件安全是指保護中間件軟件和服務的安全性&#xff0c;防止被惡意攻擊或者濫用。中間件軟件是指在操作系統和應用程序之間提供通信和集成功能…

【Go】命令行相關

查看go的環境 go env # 查看go的環境變量 goRoot # 編譯器的環境 goPath設置go module 打開cmd命令行&#xff0c;執行以下命令 go env -w GO111MODULEoff # on-打開 off-關閉 auto-自動相關命令 go build # 項目路徑下執行&#xff0c;能編譯當前go項目&#xff08;一個…