回覆列表
  • 1 # 小猴子蹦蹦噠

    首先,在自己建的公用方法的檔案中new一個新的HttpUtil.js檔案。以下為HttpUtil.js的內容:var axios = require("axios")// 配置專案根如路徑var root = "http://localhost:8090/manage"// axios請求function httpApi (method, url, params) { return new Promise((resolve, reject) => { axios({ method: method, url: url, data: method === "POST" || method === "PUT" ? params : null, params: method === "GET" || method === "DELETE" ? params : null, baseURL: root, withCredentials: false }).then((response) => {resolve(response)}).catch((error) => {reject(error)})})}// 返回在vue模板中的呼叫介面export default { get: function (url, params) { return httpApi("GET", url, params)}, post: function (url, params) { return httpApi("POST", url, params)}, put: function (url, params) { return httpApi("PUT", url, params)}, delete: function (url, params) { return httpApi("DELETE", url, params)}}

  • 中秋節和大豐收的關聯?
  • 被唐玄宗兩度肯定,公文高手杜甫卻為何當不了高官?