亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue項(xiàng)目持久化存儲(chǔ)數(shù)據(jù)的實(shí)現(xiàn)代碼

 更新時(shí)間:2018年10月01日 10:51:08   作者:水痕01  
這篇文章主要介紹了vue項(xiàng)目持久化存儲(chǔ)數(shù)據(jù)的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

方式一、使用localStorage在數(shù)據(jù)存儲(chǔ)

1、要在瀏覽器刷新的時(shí)候重新存儲(chǔ)起來(lái)

if (window.localStorage.getItem(authToken)) {
store.commit(types.SETLOANNUMBER, window.localStorage.getItem('loanNumber'));
} 

方式二、使用vue-cookie插件來(lái)做存儲(chǔ)

1、參考地址傳送門(mén)

2、安裝包

npm install vue-cookie --save

3、在store中存儲(chǔ)起來(lái)

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

Vue.use(Vuex)
var VueCookie = require('vue-cookie');

export default new Vuex.Store({
state: {
 token: VueCookie.get('token')
},
mutations: {
 saveToken(state, token) {
  state.token = token;
  // 設(shè)置存儲(chǔ)
  VueCookie.set('token', token, { expires: '30s' });
 }
},
actions: {

}
}) 

4、在登錄頁(yè)面中設(shè)置到存儲(chǔ)中

import { mapMutations } from 'vuex';
export default {
methods: {
 login() {
  this.saveToken('123')
 },
 ...mapMutations(['saveToken'])
}
}; 

方式三、使用vuex-persistedstate插件參考文件

在做大型項(xiàng)目,很多數(shù)據(jù)需要存儲(chǔ)的建議使用這種方式

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論