宗旨:总的再次过滤
# export default new Vuex.Store({ state: { name:‘‘, token:‘‘, }, mutations: {}, actions: {} }) #全局数据 #赋值 methods:{ upup:function () { let _this=this this.$http.request({ url:‘http://127.0.0.1:8000/login/‘, method:‘post‘, data:{ name:_this.name, pwd:_this.pwd } }).then(function (response) { _this.$store.state.name=response.data.name _this.$store.state.token=response.data.token }) }, } #取值 <span class="pull-right" v-if="!this.$store.state.token">
vue-cookies
-安装:npm install vue-cookies
-使用:
-store.js中导入import Cookie from ‘vue-cookies‘
-取值:Cookie.get(‘根据key值‘)
-赋值:Cookie.set(‘key值‘,‘value值‘)
定义方法
export default new Vuex.Store({
state: {
name:Cookie.get(‘name‘),
token:Cookie.get(‘token‘),
},
mutations: {
//设置cookie
set_state:function (state,response) {
state.name=response.name
state.token=response.token
Cookie.set(‘name‘,response.name)
Cookie.set(‘token‘,response.token)
},
//注销,清除所有数据(cookie,store中的数据)
clear_state:function (state) {
state.name=‘‘
state.token=‘‘
Cookie.set(‘name‘,‘‘)
Cookie.set(‘token‘,‘‘)
}
},
actions: {}
})
调用方法
if (response.data.status==100){
_this.$store.commit(‘set_state‘,response.data)
}
$Django 路飞之课程下的分类,用户登陆成功前端存cookie,
原文:https://www.cnblogs.com/3sss-ss-s/p/10177036.html