Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[웹] Vue.js(3) 본문

[웹] Vue.js(3)

코드와이 2021. 5. 13. 23:58

Vue.js

 

axios

axios 대표 API

  • axios.get('URL 주소').then().catch()
    • 해당 URL주소에 GET 요청을 보내고 성공하면 then 로직을 수행, 실패하면 catch 로직을 수행합니다.
  • axios.post('URL 주소').then().catch()
    • 요청 방식만 POST이고 나머지는 GET 방식과 동일합니다.
axios
	.get('/list')
	.then((response) => {
		this.aptList = response.data.response.body.items.item;
	})
	.catch((error) => {
		console.dir(error);
	});​

 

axios를 이용한 Spring REST API와의 통신

const addr = 'http://localhost:8097/hrmboot/api'

axios
	.get(addr)
    .then((response) => {
    	this.aptList = response.data.response.body.items.item;
	})
    .catch((error) => {
    	console.dir(error);
    });

 

 

vue-router

 

vue-router 연결

// 라우트 컴포넌트
import Main from './components/Main.js';
import Board from './components/Board.js';

// 라우터 객체 생성
const router = new VueRouter({
  routes: [
    {
      path: '/',
      name: 'main',
      component: Main,
    },
    {
      path: '/board',
      name: 'board',
      component: Board,
    },
  ],
});

 

vue-router 이동 및 렌더링

  • 네비게이션을 위해 <router-link>를 사용합니다.
  • 속성은 'to' prop을 사용합니다.
<router-link to="/list">목록</router-link>

 

$router, $route

const router = new VueRouter({
	routes: [
    	{
        	path: '/list/:id',
            component: SearchList,
		},
	],
});

// 전체 라우터 정보
// this.$router

// 현재 호출된 해당 라우터 정보
// this.$route
// this.$route.params.id
// this.$route.paht

 

 

 

 

'' 카테고리의 다른 글

[웹] Spring(3) Interceptor  (0) 2021.08.07
[웹] JPA @GeneratedValue(strategy = GenerationType.IDENTITY)  (0) 2021.07.13
[웹] Vue.js(2)  (0) 2021.05.13
[웹] Vue.js  (0) 2021.05.10
[웹] Rest API  (0) 2021.05.09