1. Fix Some I18n Warning.

2. Fix Navigation Duplicated Error When Current Route Path is `/login`.
3. Fix  Parent Level Named Route Warning.
4. Change `request` function From Promise Syntax To Await/Async.
This commit is contained in:
yaziming
2019-09-01 00:36:59 +08:00
parent 9f43e08ff9
commit fc4ebe3753
5 changed files with 58 additions and 27 deletions

View File

@@ -3,13 +3,13 @@ import router from '../router'
let baseUrl = process.env.VUE_APP_BASE_URL ? process.env.VUE_APP_BASE_URL : 'http://localhost:8000'
const request = (method, path, params, data, others = {}) => {
return new Promise((resolve, reject) => {
const request = async (method, path, params, data, others = {}) => {
try {
const url = baseUrl + path
const headers = {
'Authorization': window.localStorage.getItem('token')
}
axios({
const response = await axios({
method,
url,
params,
@@ -17,15 +17,37 @@ const request = (method, path, params, data, others = {}) => {
headers,
...others
})
.then(resolve)
.catch(error => {
console.log(error)
if (error.response.status === 401) {
router.push('/login')
}
reject(error)
})
})
// console.log(response)
return response
} catch (e) {
if (e.response.status === 401 && router.currentRoute.path !== '/login') {
router.push('/login')
}
await Promise.reject(e)
}
// return new Promise((resolve, reject) => {
// const url = baseUrl + path
// const headers = {
// 'Authorization': window.localStorage.getItem('token')
// }
// axios({
// method,
// url,
// params,
// data,
// headers,
// ...others
// })
// .then(resolve)
// .catch(error => {
// console.log(error)
// if (error.response.status === 401) {
// router.push('/login')
// }
// reject(error)
// })
// })
}
const get = (path, params) => {