前提是解决了跨域问题
①vue的代码如下:
<template>
<div>
<el-button type="primary" @click="get_houduan">get请求</el-button>
<el-button type="primary" @click="post_houduan">post请求</el-button>
</div>
</template>
<script>
export default {
methods: {
get_houduan() {
this.$axios.get("http://127.0.0.1:8000/qianduan").then((res) => {
console.log(res);
});
},
post_houduan() {
this.$axios
.post("http://127.0.0.1:8000/qianduan", {
user: 123,
pwd: 123,
})
.then((res) => {
console.log(res);
});
},
},
};
</script>
<style>
</style>
②Django的代码如下:
def qianduan(request):
try:
data = json.loads(request.body.decode("utf-8"))
print(data)
except:
pass
return JsonResponse({
'message': 'world hello'
})