# vue-project
**Repository Path**: bainan0721/vue-project
## Basic Information
- **Project Name**: vue-project
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2024-07-16
- **Last Updated**: 2024-07-16
## Categories & Tags
**Categories**: Uncategorized
**Tags**: 计算机专业vue3课设源码
## README
### 安装依赖库
```sh
npm install primeflex primeicons primevue chart.js
```
#### 安装持久化依赖插件
```shell
npm install pinia-persistedstate-plugin
```
#### 配置Pinia
在 main.js中配置
```js
// 持久化状态
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-persistedstate-plugin'
// 使用pinia持久化
const pinia = createPinia()
const persist = createPersistedState()
pinia.use(persist)
app.use(pinia)
```
#### 编写 userInfo.js
在 stores 目录下,新建 userInfo.js,并编写如下代码:
```js
import { defineStore } from "pinia";
import { ref } from "vue";
const useUserInfoStore = defineStore(
"userInfo",
() => {
//定义状态相关的内容
const info = ref({});
const setInfo = (newInfo) => {
info.value = newInfo;
};
const removeInfo = () => {
info.value = {};
};
return { info, setInfo, removeInfo };
},
{ persist: true }
);
export default useUserInfoStore;
```
#### 获取并存储用户信息
在 Layout.vue中
```js
getUser() {
//从后台获取数据
this.request.get("/user/userInfo").then(res => {
// 增加无Token时的判断和跳转
if (res.code === 401) {
ElMessage({
showClose: true,
message: res.msg,
type: "error",
duration: 1000
})
this.$router.push("/login")
} else {
// 存储用户信息
const userInfoStore = useUserInfoStore()
userInfoStore.setInfo(res.data)
this.employee = res.data
}
}).catch(e => {
ElMessage({
showClose: true,
type: "error",
message: e,
})
this.$router.push("/login")
})
}
```
#### 在Home.vue展示用户信息并修改
```js
提交修改
```
#### 修改路由表
```js
```