博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue 调用接口渲染数据
阅读量:3984 次
发布时间:2019-05-24

本文共 492 字,大约阅读时间需要 1 分钟。

首先我们用的是axios 进行调用接口的。

根据项目根目录进行安装

npm install axios -S

还有他的相关配置

1.在config/index.js中  如下

proxyTable: {

       '/api': {                                       // '/api': 匹配项
            target: "http://gohome.c.soonboom.com",   // 接口的域名
            changeOrigin: true,     // 如果接口跨域,需要进行这个参数配置
            secure: false,          // 如果是https接口,需要配置这个参数
            pathRewrite: {          // 如果接口本身没有 /api 需要通过pathRewrite来重写了地址, 如果有则不需要页面重写
                "^/api": "/api"         // 把匹配到的  api 替换成相应的值
            }
        }
    },

2.在src/mian.js中修改如下

import axios from 'axios'

Vue.prototype.$axios = axios

我们在调用接口的时候可以用GET和POST可以进行带参数。

POST:

GET:

这个一个点击事件的方法

 

转载地址:http://tqxui.baihongyu.com/

你可能感兴趣的文章
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]112. Path Sum
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]119. Pascal's Triangle II
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode BY Python]155. Min Stack
查看>>
[LeetCode By Python]167. Two Sum II - Input array is sorted
查看>>
[LeetCode By Python]168. Excel Sheet Column Title
查看>>
[LeetCode BY Python]169. Majority Element
查看>>
[LeetCode By Python]171. Excel Sheet Column Number
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
Mac删除文件&文件夹
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>