Access to XMLHttpRequest at 'http://url/fileName' from origin 'http://url:port-number' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js?b50d:210 POST http://url/fileName net::ERR_FAILED 200
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data') at eval (fileName.vue?1c92:239)
■ 에러 발생
Vue.js 3 에서 Axios의 post 혹은 get을 사용해 php에 데이터를 요청해 결과 데이터를 불러오려는데 에러가 발생하였다.
이는 BackEnd (php) 에서 url요청 허용을 해놓지 않았기 때문에 발생한 에러이다.
그렇기 때문에 php파일에서 간단하게 추가해야한다.
<?php header('Access-Control-Allow-Origin:*');
이렇게 작성하면 되는데, 만약 다른 상세한 설정(PUT, DELETE 등) 도 추가하려면 아래의 내용까지 추가해주면 된다.
npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: kiosk@0.1.0 npm ERR! Found: vue@3.2.21 npm ERR! node_modules/vue npm ERR! vue@"^3.0.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer vue@"^2.0.0" from vuex@3.6.2 npm ERR! node_modules/vuex npm ERR! vuex@"*" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /root/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2021-11-10T02_31_20_661Z-debug.log