數(shù)據(jù)請求步驟(與vue-resource略有不同):
一、axios的配置:
1、在相應的工程中 npm install axios --save(‘save’的作用是將模塊保存在package.json中,以便項目轉(zhuǎn)接時省事);

2、哪里用,那里引入即可:
import Axios from 'axios'

二、使用:
1、在組件中使用:(以QQ音樂接口為例)
let api='https://api.bzqll.com/music/tencent/songList?key=579621905&id=1147906982';
Axios.get(api).then((response)=>{
console.log(response)
}).catch((err)=>{
console.log(err)
})

代碼:
Home.vue:

<template>
<div>
<h2>這是一個首頁組件</h2>
<button @click="getData()">請求數(shù)據(jù)</button>
</div>
</template>
<script>
import Axios from 'axios'//哪里用,就在那里引用(比如,Home.vue這個組件里要用,則在此處引入)
export default {
name: "home",
data(){
return {
msg:'我是一個首頁',
list:[],
}
},
methods:{
getData(){
let api='https://api.bzqll.com/music/tencent/songList?key=579621905&id=1147906982';
Axios.get(api).then((response)=>{
console.log(response)
}).catch((err)=>{
console.log(err)
})
}
},
}
</script>
<style scoped lang="scss">
h2{
color:red;
}
</style>