-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
丁磊
authored and
丁磊
committed
Apr 24, 2016
1 parent
7c1eed9
commit e99c1bf
Showing
14 changed files
with
179 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
"url-loader": "^0.5.7", | ||
|
||
"mockjs": "^1.0.0", | ||
"react-cookie": "^0.4.5", | ||
|
||
|
||
"vue-waterfall":"^0.2.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Created by dinglei on 16/4/24. | ||
*/ | ||
import { ListResource } from './resources' | ||
|
||
export default { | ||
getLists:function () { | ||
return ListResource.get({id: '123'}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Vue from 'vue' | ||
import VueResource from 'vue-resource' | ||
import {API_ROOT} from '../../config' | ||
import { getCookie,signOut } from '../utils/authService' | ||
|
||
Vue.use(VueResource) | ||
|
||
// HTTP相关 | ||
Vue.http.options.crossOrigin = true | ||
Vue.http.options.xhr = {withCredentials: true} | ||
|
||
Vue.http.interceptors.push({ | ||
request (request) { | ||
// 这里对请求体进行处理 | ||
request.headers = request.headers || {} | ||
if (getCookie('token')) { | ||
request.headers.Authorization = 'Bearer ' + getCookie('token').replace(/(^\")|(\"$)/g, '') | ||
} | ||
return request | ||
}, | ||
response (response) { | ||
// 这里可以对响应的结果进行处理 | ||
if (response.status === 401) { | ||
signOut() | ||
window.location.pathname = '/login' | ||
} | ||
return response | ||
} | ||
}) | ||
|
||
export const ListResource = Vue.resource(API_ROOT + 'src/mock/list.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import cookie from 'react-cookie' | ||
import { CookieDomain } from '../../config.js' | ||
let cookieConfig = {} | ||
if(CookieDomain !== ''){ | ||
cookieConfig = { domain: CookieDomain } | ||
} | ||
|
||
export function saveCookie(name,value) { | ||
cookie.save(name, value, cookieConfig) | ||
} | ||
|
||
export function getCookie(name) { | ||
return cookie.load(name) | ||
} | ||
|
||
export function removeCookie(name) { | ||
cookie.remove(name, cookieConfig) | ||
} | ||
|
||
export function signOut() { | ||
cookie.remove('token', cookieConfig) | ||
} | ||
|
||
export function isLogin() { | ||
return !!cookie.load('token') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<style> | ||
</style> | ||
|
||
<template> | ||
|
||
<ul> | ||
<li v-for="item in lists"> {{item.title}}</li> | ||
</ul> | ||
|
||
</template> | ||
|
||
<script> | ||
import { getAjax } from '../vuex/actions' | ||
export default { | ||
vuex: { | ||
getters: { | ||
//lists: ({lists}) => lists | ||
lists: function (state) { | ||
console.log(state) | ||
return state.lists | ||
} | ||
}, | ||
actions:{ | ||
getAjax | ||
} | ||
}, | ||
route:{ | ||
activate ({ next }) { | ||
this.getAjax() | ||
next() | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
SUCCESS_GET_LISTS, | ||
FAILURE_GET_LISTS | ||
} from '../mutation-types' | ||
|
||
// initial state | ||
const state = { | ||
all: [] | ||
} | ||
|
||
// mutations | ||
const mutations = { | ||
[FAILURE_GET_LISTS](state){ | ||
state.items = [] | ||
}, | ||
[SUCCESS_GET_LISTS](state,action){ | ||
// console.log(state) | ||
//console.log(action) | ||
state.items = action.lists.data.data | ||
} | ||
} | ||
|
||
export default { | ||
state, | ||
mutations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters