fetch API, fetch 함수는 필수 항목인 input과 옵션인 init을 파라미터로 가지며 Response 타입을 갖는 Promise를 반환한다.
function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>
(출처: https://goodteacher.tistory.com/540)
위의 글을 확인해봤을 때 init은 옵션 값이며 그 값이 특정한게 없으면 boolean 값으로 표현한다.
그렇다면 아래의 코드를 확인해 보자면 옵션은 true값만 넣어서 GET 메소드를 그대로 호출한다.
// 기본 내용만 들어가고 민감한 내용은 삭제한 예시코드
mounted (
this.fetchinfo({ init: true })
)
methods: {
async fetchinfo(options) {
try {
const GetData = await API.GET(null, { options })
this.info = GetData.SectionData.Item
} catch (error) {
console.log(error)
}
},
}
호출을 하면 input과 init 값을 설정한다. 그 중에서 init은 옵션 객체로 요청 시 전달할 사용자 정의 속성을 설정할 수 있다. 대표적으로 설정하는 init 객체의 속성은 아래와 같다.
(출처: https://goodteacher.tistory.com/540)