【vue学习】vue axios
安装vue axios
npm install --save axios vue-axios
安装依赖
npm install
在main.js中引入
在项目中使用axios模块
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios,axios)
发送请求
-
发送get请求
registfn: function () { // GET request for remote image in node.js this.axios({ method: "get", url: "http://localhost:8089/regist?mail=" + this.mail + "&password=" + this.password, }).then(function (response) { console.log(response.data); });
-
发送post请求
axios(config) // Send a POST request axios({ method: 'post', url: '/user/12345', data: { firstName: 'Fred', lastName: 'Flintstone' } });
解决跨域问题
<!-- spring-mvc里的内容-->
<!-- 解决API接口跨域问题配置 Spring MVC 版本必须是 4.2 及以上 -->
<mvc:cors>
<mvc:mapping path="/**"
allowed-origins="*"
allowed-methods="POST, GET, OPTIONS, DELETE, PUT"
allowed-headers="Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
allow-credentials="true"
max-age="3600" />
</mvc:cors>