반응형
Access to XMLHttpRequest at 'http://localhost:3000/memos' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CORS오류 NodeJS에서 해결하는 방법 말고 Vue3에서는 proxy로 해결하는 방법이 있습니다.
해결방법
vue.config.js ( 없으면 생성해줍니다. 프로젝트 최상단 )
module.exports = {
devServer: {
proxy: {
"/api": {
target: "http://localhost:3000",
changeOrigin: true
}
}
}
}
vue
setup() {
const url = '/api';
axios.get(url + '/memos')
.then(res => {
console.log(res);
})
}
반응형
'VueJS > VueJS' 카테고리의 다른 글
[ Vue ] Vue3 v-if 내부에 element 높이값 구하기 (0) | 2022.08.01 |
---|---|
[ Vue ] Vue3 프로토타입 사용하기 (0) | 2022.08.01 |
[ Vue ] Vue3 Parsing Error : 바벨 구성요소를 찾지 못하는 오류 (0) | 2022.07.27 |
[ Vue ] Vue3 package.json 위치를 찾지 못하는 오류 (0) | 2022.07.27 |
[ Vue ] Vue3 vue-cli가 오래되었습니다 ? (0) | 2022.07.26 |