1.安装axios模块
npm install --save axios vue-axios
2.安装依赖
npm install
3.在main.js中使用axios
import axios from'axios'
import VueAxios from'vue-axios'
Vue.use(VueAxios,axios)
4.发送Ajax请求
4.1 发送axios的get请求
this.axios({
method:'get',
//get请求中的参数一定是在url之后
url:'http://localhost:8080/regist?username='+this.username+'&password'+this.password,
}).then(function(response){
console.log(response.data)
})
4.2发送axios的post请求
this.axios({
method:'post',
url:'http://localhost:8080/regist',
//post请求的参数是在data里面体现
data:{
username:this.username,
password:this.password
}
}).then(function(response){
console.log(response.data)
})
Vue中发送Ajax请求
最新推荐文章于 2025-06-08 14:56:11 发布