1、安装axios插件
npm insatll axios --save
2、在main.js中引用
import axios from 'axios'
// 只能把axios挂载到vue的原型上
Vue.prototype.$axios = axios;
3、在App.vue中使用
export default {
name: 'Index',
data () {
return {
msg: 'hello'
}
},
mounted () {
this.$axios
.get(
'../../static/test.json'
)
.then(res => {
this.msg = res.data
})
.catch(err => {
alert(err)
})
}
}