vue3 使用axios请求示例
🕙2023-03-04
Vue Get请求示例
<template>
<div>
{{ info }}
</div>
</template>
<script>
import axios from "axios";
export default {
name: "Home",
data() {
return {
info: null
}
},
mounted () {
axios.get('http://localhost:8000/v1/hello')
.then( response => {
this.info = response.data.message;
console.log(response);
}).catch( error => {
console.log(error);
});
}
}
</script>
<style lang="stylus" scoped>
</style>
Vue Post请求示例
<template>
<div>
{{ info }}
</div>
</template>
<script>
import axios from "axios";
import qs from 'qs'
export default {
name: "Home",
data() {
return {
info: null
}
},
mounted () {
let data = qs.stringify("TestGinPostAPI");
axios.post('http://localhost:8000/v1/post', data)
.then( response => {
this.info = response.data.message;
console.log(response);
}).catch( error => {
console.log(error);
});
}
}
</script>
<style lang="stylus" scoped>
</style>