티스토리 뷰
<template>
<div>
<label for="id">ID:</label>
<input id="id" type="text" v-model="id">
<label for="pw">PW:</label>
<input id="pw" type="text" v-model="pw">
<button>로그인</button>
</div>
</template>
<script>
export default {
data() {
return {
id: '',
pw: ''
}
},
}
</script>
<style scoped>
</style>
위처럼 인풋에 v-model로 data와 연결해주면 인풋에 입력할 때마다 data가 변경된다.
이제 axios를 다운로드 하자
https://axios-http.com/kr/docs/intro
시작하기 | Axios Docs
시작하기 브라우저와 node.js에서 사용할 수 있는 Promise 기반 HTTP 클라이언트 라이브러리 Axios란? Axios는 node.js와 브라우저를 위한 Promise 기반 HTTP 클라이언트 입니다. 그것은 동형 입니다(동일한 코
axios-http.com
$ npm install axios
설치에는 npm말고도 다양한 방법이 있다. 콘솔창에 넣으면 package.json dependency에서 확인이 가능하다.
추가로 이번에 로그인을 위해 가짜 api를 쓸 생각이다.
https://jsonplaceholder.typicode.com/
JSONPlaceholder - Free Fake REST API
{JSON} Placeholder Free fake and reliable API for testing and prototyping. Powered by JSON Server + LowDB. Serving ~3 billion requests each month.
jsonplaceholder.typicode.com
<template>
<form action="" @submit.prevent="login">
<div>
<label for="id">ID:</label>
<input id="id" type="text" v-model="id">
<label for="pw">PW:</label>
<input id="pw" type="text" v-model="pw">
<button type="submit">로그인</button>
</div>
</form>
</template>
<script>
import axios from 'axios'
export default {
data() {
return {
id: '',
pw: ''
}
},
methods : {
login() {
var data1 = {
id: this.id,
pw: this.pw
}
axios.post('https://jsonplaceholder.typicode.com/users', data1)
.then(res => {
console.log(res);
})
}
}
}
</script>
<style scoped>
</style>
1) form에 v-on의 축약어 @submit을 사용하며 .prevent는 event.preventDefault();를 뜻한다.
2) axios는 api 통신을 위한 라이브러리이며 url, data 방식으로 이용된다. then을 이용해서 결과 값을 받을 수 있음
'dev > vue3' 카테고리의 다른 글
created 및 컴포넌트 구조 (0) | 2025.01.07 |
---|---|
vue3 프로젝트 웹팩으로 설치 (0) | 2025.01.07 |
Vue single file component 소개 (1) | 2025.01.05 |
Vue CLI: 뷰 프로젝트 생성 도구 및 구조 약간 설명 (1) | 2025.01.04 |
same level low component끼리의 데이터 이동 (0) | 2025.01.04 |
- Total
- Today
- Yesterday
- 스프링부트
- 컨트
- jpa api
- 리터럴
- 향해99
- 향해플러스
- 항해플러스
- 향해플러스백엔드
- filter
- thymleaf
- 인터셉터
- 예외처리
- rejectValue
- 항해99
- 로그인
- Intercepter
- exception
- ArgumentResolver
- JPA
- Java
- BindingResult
- react실행
- 스프링공부
- hypertexttransferprotocol
- 백엔드 개발자 공부
- HTTP
- 백엔드 개발자 역량
- SpringBoot
- React
- reject
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |