laravel和前端方面的CORS插件,我使用Axios调用REST API
我从起源' http:// localhost:8080 ' 在' https://xx.xxxx.xx ' 处获得对XMLHttpRequest的错误访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:重定向不允许进行预检请求。
this is for a vuejs axios setup **main.js**
axios.defaults.baseURL = process.env.BASE_URL;
axios.defaults.headers.get['Accepts'] = 'application/json';
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
axios.defaults.headers.common['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
**content.vue file**
this.loading = true;
var companyId = this.$route.params.cid;
var userId = this.$route.params.uid;
const thisVue = this;
var formData = new FormData();
let data = {};
formData.append("subject", this.title);
formData.append("content", this.content);
formData.append("posting_article_url", this.blog_link);
formData.append("recruitment_tension", this.sel_recruitment_tension);
formData.append("why_hire_engineer", this.sel_company_hire_engineer);
formData.append("technique_skill", this.requiredTechniqueSkill);
formData.append("better_technique_skill",this.betterTechniqueSkillIfThereIs);
formData.append("personality", this.requiredPersonality);
formData.append("any_request", this.anyRequest);
formData.append("location", this.location);
formData.append("supplement_time", …Run Code Online (Sandbox Code Playgroud) 我正在测试使用Axios的登录组件。我尝试使用来模拟Axios axios-mock-adapter,但是当我运行测试时,仍然出现以下错误:
Error: Request failed with status code 404
Run Code Online (Sandbox Code Playgroud)
如何在测试中正确模拟Axios?
Error: Request failed with status code 404
Run Code Online (Sandbox Code Playgroud)
import Vue from 'vue'
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Login from '../../src/components/global/login/Login.vue';
import Raven from "raven-js";
import jQuery from 'jquery'
import Vuex from 'vuex'
import router from '../../src/router'
var axios = require('axios');
var MockAdapter = require('axios-mock-adapter');
describe('Login.vue', () => {
let wrapper;
let componentInstance;
let mock;
beforeEach(() => {
global.requestAnimationFrame = setImmediate,
mock = new MockAdapter(axios)
wrapper …Run Code Online (Sandbox Code Playgroud) 我添加了干预/图像包来转换 Laravel 中的图像格式。
图像转换成功,但上传后图像质量太差。
$img =(string) Image::make($image['base64'])
->resize(500, 500)->encode('jpg',100);;
$img = base64_encode($img);
Run Code Online (Sandbox Code Playgroud)