网页设计与网站建设的理解,做快递单的网站会不会是骗人的,wordpress百度分享,肉多各种地方做的网站实际开发中#xff0c;前端页面所需要的数据往往从服务器获取#xff0c;这就涉及服务器的通信 axios是一个基于promise网络请求库#xff0c;作用于node.js和浏览器 在浏览器端使用xmlhttprequests发送网络请求.自动完成json转换
axios.get(/url?id12345)
.then(function…实际开发中前端页面所需要的数据往往从服务器获取这就涉及服务器的通信 axios是一个基于promise网络请求库作用于node.js和浏览器 在浏览器端使用xmlhttprequests发送网络请求.自动完成json转换
axios.get(/url?id12345)
.then(function(response){
// 处理成功
console.log(response);
}
)
.catch(function(error){
//处理失败
console.log(error);
})
.then()functiuon(){
//总是会执行
})axios.get(/user,params{ id:12345
})
.then(function(response){
// 处理成功
console.log(response);
}
)
.catch(function(error){
//处理失败
console.log(error);
})
.then()functiuon(){
//总是会执行
})要和getmapping结合起来
axios.post(/user,
{firstname:adaw,
lastname:fff
}
)
.then(function(response){
// 处理成功
console.log(response);
}
)
.catch(function(error){
//处理失败
console.log(error);
})
.then()functiuon(){
//总是会执行
})支持async/await语法
async function getUser(){
try{const response await axios.get(/user?id123);console.log(response);
}catch(error){console.error(error);
}
}异步同调方法 async 和 await方法 取代那种.then方法 实际上.then有的多
还you其他请求方式 直接传配置项 调用不同方法.post相当于对配置项简化
axios({
method:post,
url:/user/123,
data:{
firstname:fre,
lastname:fffff
}
}
)axios.get(url[,config]) axios.post(url,data[,config])
生命周期函数 created() mounted()
网络请求一般在created创建时使用