VUE - get 、post 请求后端接口:get 、post 写法 (Axios 中文说明文档地址)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                VUE -  get 、post 请求后端接口:get 、post 写法 (Axios 中文说明文档地址)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
Axios 中文使用說明文檔地址:Axiox 中文說明文檔
我只是記錄下寫法,兩種請求都能正常運行:
1. 安裝:
npm install axios2.在 main.js 中加上以下配置:
// 用于和后臺交互,發送請求 import axios from 'axios'; axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; Vue.prototype.$axios = axios; <template><div id="box"><input type="button" @click="getdata()" value=" 小熊點點它"><!-- <h1>site : {{data}}</h1> --></div> </template><script type="text/javascript">var data = "";export default {data() {return {data};},methods: { getdata() {// get請求this.$axios.get("這里寫請求的url").then(res => {alert("請求成功,response=" + res.data);// data = res.data;console.log(res.data.navList);});} }}; </script>3. post 請求 參數組裝:?
代碼:
// 組裝參數,不直接寫在data后面var params = new URLSearchParams();params.append("account", "admin");params.append("nickname", "小熊");this.$axios({method: "post",url: this.GLOBAL.BASE_URL + "/user/getUser",data: params}).then(res => {});?
總結
以上是生活随笔為你收集整理的VUE - get 、post 请求后端接口:get 、post 写法 (Axios 中文说明文档地址)的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: QT操作sqlite数据库汇总
 - 下一篇: QT中的容器遍历