一 课程分类显示
宗旨:总的再次过滤
二 Cookie
# 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">
Vuex状态管理器stoer介绍
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) }
原文地址:https://www.cnblogs.com/3sss-ss-s/p/10177036.html
时间: 2024-10-22 12:30:25