做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

Vue項(xiàng)目使用localStorage+Vuex保存用戶登錄信息

來源:懂視網(wǎng) 責(zé)編:小OO 時(shí)間:2020-11-27 21:56:03
文檔

Vue項(xiàng)目使用localStorage+Vuex保存用戶登錄信息

本文實(shí)例為大家分享了Vue使用localStorage+Vuex保存用戶登錄信息的具體代碼,供大家參考,具體內(nèi)容如下:api.js;import axios from 'axios'const baseURL = 'http://XXX// 全局的 axios 默認(rèn)值axios.defaults.baseURL = baseURL// 登錄請(qǐng)求const loginCheck = params =>;{ return axios.post('/login'.params).then(res =>;{ return res.data })}export { loginCheck }。store.js;
推薦度:
導(dǎo)讀本文實(shí)例為大家分享了Vue使用localStorage+Vuex保存用戶登錄信息的具體代碼,供大家參考,具體內(nèi)容如下:api.js;import axios from 'axios'const baseURL = 'http://XXX// 全局的 axios 默認(rèn)值axios.defaults.baseURL = baseURL// 登錄請(qǐng)求const loginCheck = params =>;{ return axios.post('/login'.params).then(res =>;{ return res.data })}export { loginCheck }。store.js;

本文實(shí)例為大家分享了Vue使用localStorage+Vuex保存用戶登錄信息的具體代碼,供大家參考,具體內(nèi)容如下

api.js

import axios from 'axios'
const baseURL = 'http://XXX

// 全局的 axios 默認(rèn)值
axios.defaults.baseURL = baseURL

// 登錄請(qǐng)求
const loginCheck = params => {
 return axios.post('/login', params).then(res => {
 return res.data
 })
}
export { loginCheck }

store.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const actions = {}
const mutations = {
 handleUserName: (state, user_name) => {
 state.user_name = user_name
 // 把登錄的用戶的名保存到localStorage中,防止頁面刷新,導(dǎo)致vuex重新啟動(dòng),用戶名就成為初始值(初始值為空)的情況
 localStorage.setItem('user_name', user_name)
 }
}
const state = {
 user_name: '' || localStorage.getItem('user_name')
}
// getters 只會(huì)依賴 state 中的成員去更新
const getters = {
 userName: (state) => state.user_name
}

const store = new Vuex.Store({
 actions,
 mutations,
 state,
 getters
})
export { store }

login.vue

methods:{
 login(formName){
 this.$refs[formName].validate((valid) => {
 if (valid) {
 // 調(diào)用登錄請(qǐng)求接口
 loginCheck(this.form).then(res=>{
 // console.log(res);
 // 登錄成功,提示成功信息,然后跳轉(zhuǎn)到首頁,同時(shí)將token保存到localstorage中, 將登錄名使用vuex傳遞到Home頁面
 if(res.meta.status === 200){
 // 提示成功信息
 this.$message({
 message: res.meta.msg,
 type: 'success'
 });
 var that = this;
 // 跳轉(zhuǎn)到首頁
 setTimeout(function(){
 that.$router.push({name:'Home'})
 },1000)
 localStorage.setItem('token',res.data.token)
 // 將登錄名使用vuex傳遞到Home頁面
 this.$store.commit('handleUserName',res.data.username);
 }else{
 // 登錄失敗,就提示錯(cuò)誤信息
 this.$message({
 message: '登錄失敗,'+res.meta.msg,
 type: 'error'
 });
 }
 })
 } else {
 
 return false;
 }
 });
 }
 }

Home.vue

您好,{{$store.getters.username}}

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

Vue項(xiàng)目使用localStorage+Vuex保存用戶登錄信息

本文實(shí)例為大家分享了Vue使用localStorage+Vuex保存用戶登錄信息的具體代碼,供大家參考,具體內(nèi)容如下:api.js;import axios from 'axios'const baseURL = 'http://XXX// 全局的 axios 默認(rèn)值axios.defaults.baseURL = baseURL// 登錄請(qǐng)求const loginCheck = params =>;{ return axios.post('/login'.params).then(res =>;{ return res.data })}export { loginCheck }。store.js;
推薦度:
標(biāo)簽: VUE 用戶信息 項(xiàng)目
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 长岭县| 海门市| 宜川县| 永清县| 建湖县| 宜昌市| 海南省| 五华县| 普定县| 镇原县| 四平市| 延吉市| 大余县| 青阳县| 绥棱县| 吉林市| 运城市| 木里| 靖远县| 肃南| 酒泉市| 马尔康县| 蕉岭县| 涡阳县| 达拉特旗| 鹤壁市| 湘西| 甘泉县| 上杭县| 广昌县| 崇礼县| 盈江县| 定陶县| 通榆县| 眉山市| 郑州市| 黄陵县| 禹城市| 台中市| 衡南县| 包头市|