[Vue3] 가상 노드 생성하는 h()

Dohee Kang·2023년 4월 23일
0

Vue

목록 보기
26/28

1. h()

  • h()는 가상 DOM 요소를 생성하는데 사용된다.
  • 요소의 타입(필수), 속성, 자식 노드를 인수로 사용된다.
h(
  type: string | Component,
  props?: object | null,
  children?: Children | Slot | Slots
)

2. 사용 예시

const app = createApp({
  render() {
    return h('div', { id: 'app' }, [
      h('h1', 'Hello, Vue 3!'),
      h('p', 'This is an example of using the h() function.')
    ])
  }
});

app.mount('#app');
  • h()를 통해 <div> 요소를 생성하고, 'app'이라는 id 속성을 부여한다.
  • <h1><p> 요소가 자식 노드로 추가된다.
profile
오늘은 나에게 어떤 일이 생길까 ✨

0개의 댓글