- Vue 인스턴스
- 템플릿 문법
- Computed Properties and Watchers
- 클래스 / 스타일 바인딩
- Conditional Rendering
- 리스트 뿌리기
- 이벤트 핸들링
- 폼 입력 바인딩
- 반응성에 대해 좀 더 깊이 알아보기
- 트렌지션 효과
- Transitioning State
- Render 함수
- 사용자 정의 디렉티브(directive:명령어)
- 컴포넌트를 파일(뷰 파일) 하나로 작성하기
- Production 으로 디플로이 하기
- 상태 관리
- 유닛 테스트
- 서버 사이드 렌더링
- Migration from Vue 1.x
- Migration from Vue Router 0.7.x
- Migration from Vuex 0.6.x to 1.0
- 다른 프레임워크와의 비교
- Join the Vue.js Community!
In string templates, for example Handlebars, we would write a conditional block like this:
In Vue, we use the
v-if directive to achieve the same:
It is also possible to add an “else” block with
v-if is a directive, it has to be attached to a single element. But what if we want to toggle more than one element? In this case we can use
v-if on a
<template> element, which serves as an invisible wrapper. The final rendered result will not include the
You can use the
v-else directive to indicate an “else block” for
v-else element must immediately follow the
v-if element - otherwise it will not be recognized.
Another option for conditionally displaying an element is the
v-show directive. The usage is largely the same:
The difference is that an element with
v-show will always be rendered and remain in the DOM;
v-show simply toggles the
display CSS property of the element.
v-show doesn’t support the
<template> syntax, nor does it work with
v-if is “real” conditional rendering because it ensures that event listeners and child components inside the conditional block are properly destroyed and re-created during toggles.
v-if is also lazy: if the condition is false on initial render, it will not do anything - the conditional block won’t be rendered until the condition becomes true for the first time.
v-show is much simpler - the element is always rendered regardless of initial condition, with just simple CSS-based toggling.
v-if has higher toggle costs while
v-show has higher initial render costs. So prefer
v-show if you need to toggle something very often, and prefer
v-if if the condition is unlikely to change at runtime.