Please advise
how to write the following functions using the async function. methods: {
getList() {
this.listLoading = true
fetchList(this.listQuery).then(response => {
this.list = response.data.items
this.total = response.data.total
// Just to simulate the time of the request
setTimeout(() => {
this.listLoading = false
}, 1.5 * 1000)
})
},
//fetchList
export function fetchList(query) {
return request({
url: "/article/list",
method: "get",
params: query
})
}
//request
import axios from "axios"
import { Message } from "element-ui"
import store from "@/store"
import { getToken } from "@/utils/auth"
// create an axios instance
const service = axios.create({
baseURL: process.env.BASE_API, // apibase_url
timeout: 5000 // request timeout
})
// request interceptor
service.interceptors.request.use(config => {
// Do something before request is sent
if (store.getters.token) {
// token-- ["X-Token"]key
config.headers["X-Token"] = getToken()
}
return config
}, error => {
// Do something with request error
console.log(error) // for debug
Promise.reject(error)
})
// respone interceptor
service.interceptors.response.use(
response => response,
error => {
console.log("err" + error) // for debug
Message({
message: error.message,
type: "error",
duration: 5 * 1000
})
return Promise.reject(error)
})
export default service