본문 바로가기

웹 퍼블리셔 기록/Vue3

[Vue3 + TS] Event Target 에러

1. (event)에 타입 Event 설정해주기

2. event.target.textContent 하면 

Property 'textContent' does not exist on type 'EventTarget' 에러 뜸

(event.target as HTMLLIElement).textContent 로 작성해주기

const dpText = ref<any>('Dropdown Text');

const menuClik = (event: Event) => {
  const eText = (event.target as HTMLLIElement).textContent;
  dpText.value = eText;

};

 

 

<ul class="dp-bottom">
  <li v-for="(item, index) in items" :key="index" @click="menuClik">
    {{ item.menu }}
  </li>
</ul>