首先要store创建状态
store.js 文件
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//创建VueX对象
const state = {
routerName:'', // 当前路由
routerUrl:'', // 当前url
asyncMethods:[], // 页面访问的数据接口
startTime:new Date().getTime() // 开始进入页面时间
}
const actions = {
notifyBackend (store,newRouter) {
const {
commit, state } = store;
let param = {
'routerName':newRouter.routerName, // 页面名
'routerUrl':newRouter.routerUrl, // 页面url
'asyncMethods':state.asyncMethods, // 页面访问数据集合
'time':new Date().getTime()-state.startTime, // 页面访问时间
}
console.log('======================',param)
// axios.post(url,param).then(res => {
// })
commit('reset',newRouter); // 初始化数据
},
addAsyncMethods(context,method){
context.commit('addAsyncMethods',method); // 每请求一次数据 异步向集合添加一次