一、编写一个配置类,并且注册CorsFilter:

注意允许跨域的域名不要写错

@Configuration
public class ZysuyuanCorsConfiguration { @Bean
public CorsFilter corsFilter() {
// 初始化cors配置对象
CorsConfiguration corsConfiguration = new CorsConfiguration();
// 允许跨域的域名,如果要携带cookie,不能写*,*代表所有域名都可以跨域访问
// corsConfiguration.addAllowedOrigin("http://localhost:10008");
// 本机使用nginx测试
corsConfiguration.addAllowedOrigin("http://localhost:8778");
// corsConfiguration.addAllowedOrigin("http://localhost:8778");
corsConfiguration.setAllowCredentials(true); // 允许携带cookies
corsConfiguration.addAllowedMethod("*"); // 代表所有的请求方法:get、post、put、delete
corsConfiguration.addAllowedHeader("*"); // 允许携带任何头信息 // 初始化cors配置源对象
UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
configurationSource.registerCorsConfiguration("/**",corsConfiguration); // 返回corsFilter实例,参数:cors配置源对象
return new CorsFilter(configurationSource);
}
}

二、编写vue的axios请求

注意:如果使用vue2.0中使用axios进行(put,post请求时),遇到415错误(参考:https://www.cnblogs.com/shuaifing/p/7921102.html

解决办法:在axios的第三个参数config中,设置请求头信息'Content-Type': 'application/json;charset=UTF-8'

    insertDevice(query) {
return request({
url: '/item/device/save',
method: 'post',
data: JSON.stringify(query),
headers : {
'Content-Type' : 'application/json;charset=UTF-8' // 注意此处的头信息要写为application/json;charset=UTF-8
}
})
}

补充:

vue中子组件调用父组件的方法(参考:https://juejin.im/post/5c1370365188250f73759a79

1、$emit方法

父:

@fselect绑定父组件中的searchBydeviceName方法

 <add-new
ref="feditForm"
@fselect="searchBydeviceName"
@close="closeEditor"
:isEdit="isEdit"
:addnewData.sync="fpojo"
></add-new>

子组件调用:

this.$emit("fselect");
 
....以后用到再更新

记录:使用springboot的cors和vue的axios进行跨域的更多相关文章

  1. .net core3.1 webapi + vue.js + axios实现跨域

    我所要讲述的是,基于.net core3.1环境下的webapi项目,如何去使用axios对接前端的vue项目 既然谈到axios,这里贴出axios的官方文档地址: http://www.axios ...

  2. 4.vue引入axios同源跨域

    前言: 跨域方案有很多种,既然我们用到了Vue,那么就使用vue提供的跨域方案. 解决方案: 1.修改HttpRequestUtil.js import axios from 'axios' expo ...

  3. vue 使用axios 出现跨域请求的两种解决方法

    最近在使用vue axios发送请求,结果出现跨域问题,网上查了好多,发现有好几种结局方案. 1:服务器端设置跨域 header(“Access-Control-Allow-Origin:*”); h ...

  4. Vue(项目踩坑)_解决vue中axios请求跨域的问题

    一.前言 今天在做项目的时候发现axios不能请求跨域接口 二.主要内容 1.之前直接用get方式请求聚合数据里的接口报错如下 2.当前请求的代码 3.解决方法 (1)在项目目录中依次找到:confi ...

  5. vue.js axios实现跨域http请求接口

    跨域post实例,用到了qs组件来避开ajax信使请求,并兼容Android. import axios from 'axios'; import qs from 'qs'; axios.post(' ...

  6. 前端vue开发中的跨域问题解决,以及nginx上线部署。(vue devServer与nginx)

    前言 最近做的一个项目中使用了vue+springboot的前后端分离模式 在前端开发的的时候,使用vue cli3的devServer来解决跨域问题 上线部署则是用的nginx反向代理至后台服务所开 ...

  7. Vue解决接口访问跨域问题

    随手摘录 Vue解决接口访问跨域问题 1.打开 config -> index.js 2. 找到proxyTable 3.粘贴 如下代码,'https://www.baidu.com'换成要访问 ...

  8. vue.js学习之 跨域请求代理与axios传参

    vue.js学习之 跨域请求代理与axios传参 一:跨域请求代理 1:打开config/index.js module.exports{ dev: { } } 在这里面找到proxyTable{}, ...

  9. Springboot html vue.js 前后分离 跨域 Activiti6 工作流 集成代码生成器 shiro 权限

    官网:www.fhadmin.org 特别注意: Springboot 工作流  前后分离 + 跨域 版本 (权限控制到菜单和按钮) 后台框架:springboot2.1.2+ activiti6.0 ...

随机推荐

  1. NX二次开发-UFUN链表UF_MODL_create_list等用法

    NX9+VS2012 #include <uf.h> #include <uf_modl.h> #include <uf_curve.h> #include < ...

  2. Try running RemoteDll as Administrator

    在使用RemoteDll注入动态库的时候发现注入有的动态库会提示下面的错误, LoadLibrary on remote process [1968 - Explorer.exe] failed. T ...

  3. 去掉Word 标题编号变成黑框

    问题: 在使用Word编写文档时,提前拟好的标题编号会突然变成黑框(黑色的方框,黑色的矩形),如下图 解决方案: 1.将光标定位到标题中,紧邻黑框的右侧 2.按键盘左方向键使方框变成黑色 3.按键盘的 ...

  4. (转)coures包下载和安装 可解决报错ImportError: No module named '_curses'

    原创文章,转载请注明出处. coures curses 库 ( ncurses )提供了控制字符屏幕的独立于终端的方法.curses 是大多数类似于 UNIX 的系统(包括Linux)的标准部分,而且 ...

  5. Allow Pin Swapping Using these Methods options

    Frm:http://techdocs.altium.com/display/ADOH/Pin,+Pair+and+Part+Swapping#Pin,PairandPartSwapping-Swap ...

  6. AtCoder ABC 127F Absolute Minima

    题目链接:https://atcoder.jp/contests/abc127/tasks/abc127_f 题目大意 初始状态下$f(x) = 0$,现在有 2 种模式的询问,第一种以“1 a b” ...

  7. CentOS7 相关配置

    nginx 1.在线安装nginx yum install nginx 2.启动nginx服务 systemctl start nginx 3.防火墙设置 打开http防火墙:firewall-cmd ...

  8. MySQL初步理解,简易单表增删改查

    什么是数据库? 存储数据的仓库,本质是一个文件系统,封装了算法和文件之前数据的存储模式 阶段1:集合 数组 变量 缺点:数据存储在内存中,不能实现数据的持久化存储 阶段2:IO流 结合文件 .txt ...

  9. linux centos 装g++安装不了

    今天需要编译一个项目的时候在装g++都装不上, [root@master hadoop]# yum install g++ Loaded plugins: fastestmirror, refresh ...

  10. 14-MySQL-Ubuntu-数据表的查询-范围查询(三)

    范围查询 1,不连续查询-in, not in 查询年龄是12,18,34的学生姓名和年龄信息 select name,age from students where age in (12,18,34 ...