亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用Vue-axios進(jìn)行數(shù)據(jù)交互的方法

 更新時(shí)間:2022年03月08日 09:48:12   作者:程序猿-張益達(dá)  
這篇文章主要介紹了使用Vue-axios進(jìn)行數(shù)據(jù)交互詳情,文章圍繞Vue-axios進(jìn)行數(shù)據(jù)交互的相關(guān)資料展開詳細(xì)內(nèi)容,需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)或工作有所幫助

1、安裝axios

  • 打開cmd命令行工具
  • cd到項(xiàng)目目錄
  • 輸入以下命令
npm install axios

提示安裝完成以后,打開main.js

輸入以下代碼:

import axios from 'axios'

接著在底下輸入:

Vue.prototype.$axios = axios

配置就完事了

2、axios的使用

this.$axios({
? ? ? ? method: 'post',//交互方式
? ? ? ? url: '/api/ImgHandle',//url地址
? ? ? ? data: {page: page}//需要交互的數(shù)據(jù)
? ? ? }).then((res) => {
? ? ? ? console.log(res)//成功 ? res為返回的結(jié)果
? ? ? }).catch((error) => {
? ? ? ? console.log(error)//失敗 ? 打印異常
? ? ? })

3、講一下代理proxyTable的使用

一般在開發(fā)時(shí),地址都在本地,會出現(xiàn)跨域報(bào)錯,報(bào)錯示例如下:

Failed to load http://192.168.1.111:8888/console/good/front/classList:
 Response to preflight request doesn’t pass access control 
check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
 Origin ‘http://localhost:8081’ is therefore not allowed access. 
 If an opaque response serves your needs, 
 set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

如果后端不修改,那就前端操作修改一下:

  • 找到 config/index.js
  • 找到 proxyTable進(jìn)行修改
?proxyTable: {
? ? ? '/api': { ?//使用"/api"來代替"http://www.xxx.com/"
? ? ? ? target: 'https://www.xxx.com/', //源地址
? ? ? ? changeOrigin: true, //改變源
? ? ? ? pathRewrite: {
? ? ? ? ? '^/api': 'https://www.xxx.com/' //路徑重寫
? ? ? ? }
? ? ? }
? ? },

然后重新運(yùn)行一下,即可生效,操作失敗就再檢查一下代碼

到此這篇關(guān)于使用Vue-axios進(jìn)行數(shù)據(jù)交互的方法的文章就介紹到這了,更多相關(guān)Vue-axios數(shù)據(jù)交互內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論