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请求
最新推荐文章于 2023-02-02 11:37:51 发布