axios.get(URL) => Promise 객체 return => then, catch 사용 가능
Vue에서 권고하는 Promise 기반 HTTP 통신 라이브러리로 문서화가 잘 되어있고 API가 다양합니다.
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"><
npm install axios
axios('url'); // default : get
axios.get('url').then().catch(); // get요청
axios.post('url').then().catch(); // post요청
axios.put('url').then().catch(); // post요청
axios.delete('url').then().catch(); // post요청
// axios({옵션 속성(config)})
axios({
method: 'post',
url: '/user',
data: {
name: '홍길동',
userid: 'hong123'
}
});
axios({
method : 'get'
url : '/user/velog'
responseType : 'json'
})
.then(function(response){
// logic
});
요지는 지정한 vue에 component를 갖다 붙여 연결하는 것!
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@3.5.3/dist/vue-router.js"></script>
npm install vue-router
<a>
태그로 렌더링됩니다.)to
prop을 사용const router = new VueRouter({
routs : [
...,
{
path: '/board',
name: 'board',
component : Board,
},
{
path: '/board/:no',
name: 'boardView',
component : BoardView,
},
...
],
});
// 연결 예시 /boardview
<router-link :to="{name: 'boardview', params: {no: 3}}">3번 게시글</router-link>
<a @click="$router.push({name:'boardview', params: {no: 3}});">3번 게시글</a>
// 쿼리스트링으로 넘길 수도 있다. 이때 url = /boardview?no=3
<router-link :to="{name: 'boardview', query: {no: 3}}">3번 게시글</router-link>
{
path: "/board",
name: "board",
component: () => import("@/views/AppBoard.vue"),
redirect: "/board/list",
children: [
{
path: "list",
name: "boardlist",
component: () => import("@/components/board/BoardList"),
},
{
path: "write",
name: "boardwrite",
component: () => import("@/components/board/BoardWrite"),
},
{
path: "view/:articleno",
name: "boardview",
component: () => import("@/components/board/BoardView"),
},
{
path: "modify/:articleno",
name: "boardmodify",
component: () => import("@/components/board/BoardModify"),
},
{
path: "delete/:articleno",
name: "boarddelete",
component: () => import("@/components/board/BoardDelete"),
},
...
],
},