뷰 인스턴스 설정 객체에는 el, data 말고도 render
함수가 존재한다.
— createElement 같은 돔 생성 함수를 인자로 주입받아서, h() 컴포넌트 설정 객체를 넘겨주면 컴포넌트에 화면을 그린다.
const NotFound = { template: '<p>Page not found</p>' }
const Home = { template: '<p>home page</p>' }
const About = { template: '<p>about page</p>' }
const routes = {
'/': Home,
'/about': About
}
new Vue({
el: '#app',
data: {
currentRoute: window.location.pathname
},
computed: {
ViewComponent () {
return routes[this.currentRoute] || NotFound
}
},
render (h) { return h(this.ViewComponent) }
})
모든 element는 하나의 node이다. (텍스트 및 주석도 모두 node)
Vue는 수동으로 업데이트 할 필요없다.
수정하고자 하는 HTML 템플릿을 작성하면 대신 업데이트한다.