一、vue-cli使用aios

1、安装命令: cnpm instal axios –save

2、main.js引入全球使用

//axios

import axios from ‘axios ‘

Vue.prototype.$axios=axios

3、在组件或页面上使用

methods:

{

testaxios 1:功能(

控制台. log (‘ test ); this.$axios(method:’get ),URL : ‘ data/person data.JSON ‘ }.then ) function (响应) console.)

二、axios配置开发环境要求跨域代理

打开config/index.js

在其中找到proxyTable{},然后更改为:

代理表: {

‘/api’: {

target : ‘ http://localhost :8085 ‘,//设置调用接口的域名和端口号的http changeOrigin: true,path rewrite 3360 { ‘ ^/aa 例如,调用’ http://40.00.100.10033603002/user/add ‘直接写’‘/api/user/add ‘就可以了。 }

2、使用

methods:

{

testaxios 1:功能(

控制台. log (‘ test ); this.$axios(method:’post ‘,URL : ‘ http://localhost 33608085/screen/sel caugh ‘ } ) then ) function ) resstion

三. axios传

1 :默认情况下,vue官方推荐组件axios是提交JSON字符串,因此可以直接将JSON字符串连接在url后面,直接导入JSON对象

let postData={

公司代码: ‘ tur ‘,

用户名称: ‘ 123456789123456789 ‘,

password:’123456 ‘

}

axios.get (/API/yt _ API/log in/dolog in ),

params: {

.后数据、

}

() )

. then (功能(响应) {

控制台. log (1) ) )。

控制台. log (响应;

() )

. catch (功能(错误) {

控制台. log (error;

);