v-model
<input v-model="inputValue"/>
@click
<button @click="addItem">add</button>
v-for
<ListItem v-for="(value,index) in listArray" :key="index" :text="value"/>
props, state
props는 배열보다는 객체를 쓰는게 좋음
<template>
<li>{{text}}</li>
</template>
<script>
export default {
props:["text"]
}
</script>
<template>
<li>{{text}}</li>
</template>
<script>
export default {
props:{
text:{
type:Number,
required:true,
default:'hello'
}
}
}
</script>
<ListItem v-for="(value,index) in listArray" :key="index" :text="value === '' ? undefined : value"/>
type을 Number로 명시해주면 다른타입일때 에러가나서 알려줌
required:true는 아무값도 입력안하면 에러남
default는 아무값도 입력안하면 'hello'로 입력됨
:변수명안에는 명사값(?)만 들어간다
예제
todoList
@emit
상위 컴포넌트에 데이터를 넘겨줄때 유용함
기존 todoList에 Delete 기능을 추가하면서 활용한 예제를 보면 이해가됨
https://github.com/LeeEugene1/vueStudy
반응형
'Frontend > React' 카테고리의 다른 글
[오류해결] You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0). (0) | 2022.01.23 |
---|---|
리덕스 기초 (0) | 2022.01.23 |
Counter 리액트 (0) | 2020.10.19 |
리액트 명함리스트 (0) | 2020.10.16 |
e.target (0) | 2020.10.11 |