vuex结合localStoarge实现对数据的存储



import Vue from 'vue';

const state = {
title: []
};

export const getters = {
title(state){
if(state.title.length==0){
state.title=JSON.parse(localStorage.getItem('title'))
}
return state.title;
}
};

export const actions = {
getTitle(commit){
Vue.http.get(‘api’,data).then(function(res){
commit('get_title',name)
})
}
};

export const mutations = {
get_title(state,name){
state.title = name;
localStorage.setItem('title',JSON.stringify(state.title))
}
};

export default {
state,
getters,
actions,
mutations
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM