vue 上传图片及跨域

时间:2022-08-29 18:30:37
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res; HttpServletRequest request = (HttpServletRequest) req; response.setHeader("Access-Control-Allow-Headers", "X-Requested-With, Accept, Content-Type,Authorization"); response.setHeader("Access-Control-Allow-Methods", "GET, POST,OPTIONS"); String origin = request.getHeader("Origin"); response.setHeader("Access-Control-Allow-Origin", "127.0.0.1"); // 是否允许浏览器携带用户身份信息(cookie) response.setHeader("Access-Control-Allow-Credentials", "true");
// 图片上传返回第一次的option请求 if ("OPTIONS".equals(request.getMethod())) { response.setStatus(200); return; }
}

  后台过滤器配置

 

 

<Upload
                name="file"
                :format="['jpg','jpeg','png']"
                :show-upload-list="false"
                :before-upload="beforeupload"
                :on-success="handleSuccess"
                :max-size="2048"
                :action="actionBaseUrl"
                :with-credentials="credentials"
                style="margin-left: 10px;display: inline-block;">
                <Button icon="ios-cloud-upload-outline">上传图片</Button>
              </Upload>

 

  iview 上传图片组件