vue使用axios获取后台数据

在使用Vue.js进行前端开发的时候,有时候需要从后台获取数据,在这里我是用的是axios的方法。

1
2
//在需要交互的.vue文件中添加引用
import axios from 'axios';
1
2
3
4
5
6
7
8
9
10
//然后在methods中使用get方法对数据进行获取
methods: {
getData(){
axios.get('url').then((response)=>{
//do something with the response
}).catch((response)=>{
console.log(response);
})
}
}