0917自我總結
Vue-cli中axios傳參的方式以及后端取的方式
一.傳參
- params是添加到url的請求字符串中的,用於get請求。
- data是添加到請求體(body)中的, 用於post請求。
首先現在main.js進行配置
import axios from 'axios'
Vue.prototype.$axios = axios;
如:get請求
<script>
......
事件的函數() {
this.$axios({
url: xxxxx
method: 'get',
params: {
變量名: 變量值
}
}).then(response => {請求成功邏輯代碼})..catch(error => {請求失敗邏輯代碼})
}
........
</script>
如:post請求
<script>
......
事件的函數() {
this.$axios({
url: xxxxx
method: 'post',
data: {
變量名: 變量值
}
}).then(response => {請求成功邏輯代碼})..catch(error => {請求失敗邏輯代碼})
}
........
</script>
二.后台獲取
如果是params傳參后台取request.GET或者request.query_params
如果是data傳參后台取request.data
