Axios demo
ChuangWANG
Posted on May 2, 2021
Offical Axios website: https://zetcode.com/javascript/axios/
get_req.js
const axios = require('axios');
axios.get('http://localhost:3210/hehe/haha').then(resp => {
console.log(resp.data);
}).catch((reject)=>console.log(reject));
get_req_async.js
const axios = require('axios');
async function makeGetRequest() {
let res = await axios.get('http://webcode.me');
let data = res.data;
console.log(data);
}
makeGetRequest();
basic_api.js
const axios = require('axios');
async function makeRequest() {
const config = {
method: 'get',
url: 'http://webcode.me'
}
let res = await axios(config)
console.log(res.status);
}
makeRequest();
head_req.js
const axios = require('axios');
async function makeHeadRequest() {
let res = await axios.head('http://localhost:3210/hehe/haha');
console.log(`Status: ${res.status}`)
console.log(`Server: ${res.headers.server}`)
console.log(`Date: ${res.headers.date}`)
}
makeHeadRequest();
Http in webmanager frontend POST:
const { data } = await this.$http({
url: '/common/resource/delete',
method: 'post',
data: idList
})
if (data.code === "200") {
that.$message("删除成功")
} else {
that.$message("删除失败")
}
Http in webmanager frontend GET:
async getUserInfo () {
const { data } = await this.$http({
url: this.$http.adornUrl('/sys/user/info'),
method: 'get',
params: this.$http.adornParams()
})
if (data && data.code === 200) {
this.loading = false
this.userId = data.user.userId
this.userName = data.user.username
}
}
const { data } = await this.$http({
url: this.$http.adornUrl('/sys/user/password'),
method: 'post',
data: this.$http.adornData({
password: this.dataForm.password,
newPassword: this.dataForm.newPassword
})
})
if (data && data.code === 200) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$nextTick(() => {
this.mainTabs = []
clearLoginInfo()
this.$router.replace({ name: 'login' })
})
}
})
} else {
this.$message.error(data.message)
}
async getFirstList (page) {
const { data } = await this.$http(
{
url: '/content/page/list',
type: 'get',
params: {
page: page,
limit: 10
}
}
)
this.firstPannelPaginationSize = data.data.totalCount
this.firstPannelPaginationNum = page
this.firstPannelTableData = data.data.list
},
💖 💪 🙅 🚩
ChuangWANG
Posted on May 2, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
reactnative I have an error when installing and using the react-native-bluetooth-serial-next library on an ios device.
November 29, 2024
programming Supercharge Your Node.js: WebAssembly's Game-Changing Performance Boost
November 28, 2024