[toc]
### 1. 刪除忘記密碼和豎線
### 2. 注冊賬戶文字切換 與 登錄按鈕文字切換
```
1. 在data內定義 type : "login",
2. <a href="#" class="ml-auto small" @click="changeType">
3. changeType(){
this.type = this.type == "login" ? "reg" : "login"
},
4. <a href="#" class="ml-auto small" @click="changeType">
{{type == "login" ? "注冊賬戶" :"立即登錄" }}
</a>
<Button type="primary" long @click="handleSubmit('formItem')">
{{type == "login" ? "登 錄" :"注 冊" }}
</Button>
```
### 3. 實現表單注冊框確認密碼
```
<Form ref="formItem" :label-width="0" :model="formItem" :rules="rules">
<FormItem prop="username">
<Input v-model="formItem.username" placeholder="請輸入用戶名..."></Input>
</FormItem>
<FormItem prop="password">
<Input type="password" v-model="formItem.password" placeholder="請輸入密碼..."></Input>
</FormItem>
<FormItem prop="repassword" v-if="type === 'reg'">
<Input type="password" v-model="formItem.repassword" placeholder="請輸入確認密碼..."></Input>
</FormItem>
<div class="d-flex align-items-center mb-2">
<Checkbox v-model="formItem.remember">自動登錄</Checkbox>
<a href="#" class="ml-auto small" @click="changeType">
{{type == "login" ? "注冊賬戶" :"立即登錄" }}
</a>
</div>
<FormItem>
<Button type="primary" long @click="handleSubmit('formItem')">
{{type == "login" ? "登 錄" :"注 冊" }}
</Button>
</FormItem>
</Form>
repassword: [{
required: true,
message: '請輸入確認密碼...',
trigger: 'blur'
},
{
type: 'string',
min: 6,
message: '密碼長度不能小于6位',
trigger: 'blur'
}
]
```
### 4. 實現登錄與注冊的數據交互
```
handleSubmit(name) {
this.$refs[name].validate((valid) => {
if (valid) {
this.$Message.success('Success!');
let text = this.type == "login" ? "登錄" : "注冊"
this.axios.post("/api/" + this.type,this.formItem).then(res=>{
if(this.type == "reg"){
this.$Message.success(text + "成功");
this.type = "login"
}else{
//存儲登錄的狀態
//跳轉到首頁
this.$router.push({name : "index"})
}
}).catch(err=>{
})
} else {
this.$Message.error('Fail!');
}
})
}
```
### 5. 存儲登錄狀態
```
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
state: {
user : null
},
mutations: {},
actions: {
//存儲登錄狀態
login({state},user){
state.user = user;
window.localStorage.setItem("user",JSON.stringify(user));
window.localStorage.setItem("token",user.token);
}
},
modules: {}
});
```
```
handleSubmit(name) {
this.$refs[name].validate((valid) => {
if (valid) {
this.$Message.success('Success!');
let text = this.type == "login" ? "登錄" : "注冊"
this.axios.post("/api/" + this.type,this.formItem).then(res=>{
if(this.type == "reg"){
this.$Message.success(text + "成功");
this.type = "login"
}else{
//存儲登錄的狀態
this.$store.dispatch("login",res)
//跳轉到首頁
this.$router.push({name : "index"})
}
}).catch(err=>{
})
} else {
this.$Message.error('Fail!');
}
})
}
```
- 第一章 VUE-CLI+IVIEW進行項目初始化
- 1.1 使用vue-cli4創建項目
- 1.2 引入iview組件庫
- 1.3 引入bootstrap4和圖標庫
- 1.4 安裝和配置vue-router
- 第二章 pc端登錄頁開發
- 2.1 pc端登錄頁開發(一)
- 2.2 pc端登錄頁開發(二)
- 2.3 pc端登錄頁開發(三)
- 第三章 pc端全局布局開發
- 3.1 pc端全局布局開發(一)
- 3.2 pc端全局布局開發(二) 頂部導航
- 第四章 pc端側邊欄開發
- 4.1 pc端側邊欄開發(一) 菜單
- 4.2 pc端側邊欄開發(二) 容量提示
- 第五章 pc端文件列表開發
- 5.1 pc端文件列表開發(一) 操作條
- 5.2 pc端文件列表開發(二) 列表(1)
- 5.3 pc端文件列表開發(三) 列表(2)
- 第六章 封裝多功能文件列表組件
- 6.1 封裝文件列表組件(一)
- 6.2 封裝文件列表組件(二) 刪除
- 6.3 封裝文件列表組件(三) 多選操作
- 6.4 封裝文件列表組件(四) 重命名
- 6.5 封裝文件列表組件(五) 圖片預覽
- 第七章 前端數據交互開發
- 7.1 pc端交互-引入axios和vuex
- 7.2 pc端交互-注冊登錄
- 7.3 pc端交互-初始化和退出登錄
- 7.4 pc端交互-攔截器完善
- 7.5 權限驗證
- 7.6 pc端交互-獲取文件列表
- 7.7 pc端交互-創建文件夾
- 7.8 上傳文件
- 7.9 pc端交互-文件重命名
- 7.10 pc端交互-批量刪除
- 7.11 pc端交互-搜索文件
- 7.12 pc端交互-切換目錄
- 7.13 pc端交互-優化體驗和篩選類型
- 7.14 pc端交互-下載文件
- 7.15 pc端交互-生成分享鏈接
- 7.16 pc端交互-我的分享列表
- 7.17 pc端交互-查看分享
- 7.18 pc端交互-保存我的網盤
- 第八章 項目打包與部署
- 8.1 部署前環境搭建
- 8.2 部署pc端部分