반응형
Vue를 사용하여 개발할 경우 Request URL GET Query parameter를 전달해야 할 경우가 있다.
검색 조건이 2개 이상인 경우
예를 들어
http://localhost:8000/price?large=09&mid=01
위와 같은 URL를 만들어 서버를 호출해야 할 경우
아래 예제는 vuex와 axios를 사용하였다.
axios 사용 관련 예제코드는 아래 글을 참고하면 좋을 것 같다.
12. Vue3 + Nodejs 연동
이번은 Vue3와 Nodejs와 연동하는 것에 대해 소개한다. Nodejs는 다른 블로그에서도 많이 소개를 하니 비슷하게 구축을 하면 될것이다. Nodejs 구축 및 Vue3 axios 설치 Vue3에서 Nodejs 와 연동하기 위해 axios
datapuzzler.tistory.com
주요 예제 코드는 다음과 같다.
// xx.vue 파일에서 GetPrice 호출
store.dispatch("GetPrice", {
large : '09',
mid: '01'}
);
// store.js 내용
GetPrice({commit}, {large, mid}){
return axiosClient
.get("/price", {params: {large:`${large}`, mid:`${mid}`}}) // Get Query parameter
.then((res) =>{
commit("setResData", res.data);
return res;
})
.catch((err)=>{
return err;
});
},
get("/price", {params: {large:`${large}`, mid:`${mid}`}})
이 부분을 잘 변형해서 사용하면 Vue에서 Get Query Parameter를 만드는 것이 어렵지 않을 것이다.
반응형
'dev' 카테고리의 다른 글
d3.js xAxis scaleTime() 사용시 날짜 포맷 처리 (0) | 2023.06.03 |
---|---|
Vue Router params 데이터 처리 방법 (0) | 2023.05.29 |
Vue3 + three.js optimization 예제 코드 (0) | 2023.05.11 |
vue3 + three.js shadows 예제 코드 (0) | 2023.05.09 |
18. Vue3 + D3.js 코로나 감염 공공데이터 예제 코드 최종 (0) | 2023.05.05 |