vue ---通過API接口獲取數據


1. 配置axios

```

import axios from 'axios'`

 


```

2. 配置根路徑

```

axios.defaults.baseURL = '【接口網址】'
axios.interceptors.request.use(config => {
// console.log(config)
config.headers.Authorization = window.sessionStorage.getItem('token')
// 在最后必須 return config
return config
})
Vue.prototype.$http = axios

 

```

3. 獲取數據

```

async 【函數名】() {
const { data: res } = await this.$http.get('menus')
//判斷狀態
if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
this.menulist = res.data
console.log(res)
},

 


```

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM