日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

axios请求数据

發布時間:2025/6/17 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 axios请求数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Element UI手冊:cloud.tencent.com/developer/d… 中文文檔:element-cn.eleme.io/#/zh-CN github地址:github.com/ElemeFE/ele…


1:進入項目,npm安裝

npm install axios --save 復制代碼

2.在main.js下引用axios

import axios from 'axios' 復制代碼

3:準備json數據 自己寫了一個json數據,放在服務器上,現在要通過vue項目調用數據 www.intmote.com/test.json

4:跨域問題,設置代理,利用proxyTable屬性實現跨域請求 在config/index.js 里面找到proxyTable :{} ,然后在里面加入以下代碼

proxyTable: {'/api': {target: 'http://www.intmote.com',//設置你調用的接口域名和端口號 別忘了加httpchangeOrigin: true,//允許跨域pathRewrite: {'^/api': '' //這個是定義要訪問的路徑,名字隨便寫 }} }, 復制代碼

5:打開一個界面User.vue,開始寫請求數據的方法

methods: {getData() {axios.get('/api/test.json').then(response => {console.log(response.data);}, response => {console.log("error");});}} 復制代碼

User.vue參考代碼:

<template><div id="app"></div> </template> <script>import axios from "axios";export default {name: "app",data() {return {itemList: []}},mounted() {this.getData();},methods: {getData() {axios.get('/api/test.json').then(response => {console.log(response.data);}, response => {console.log("error");});}}} </script>復制代碼

6:再次運行 npm run dev

這個時候,我們可以看見,請求的數據


原文作者:祈澈姑娘

轉載于:https://juejin.im/post/5cebad275188252dda0afd45

總結

以上是生活随笔為你收集整理的axios请求数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。