:::

7. 點擊時,利用 $event 取得點擊事件及參數

  1. 父元件 App.vue
    <script>
    import EventBack from "@/components/EventBack.vue";
    
    export default {
      components: {
        EventBack,
      },
      setup() {
        const handleEventBack = (n, m, e) => {
          console.log(n);
          console.log(m);
          console.log(e);
          console.log(e.target);
        };
    
        return { handleEventBack };
      },
    };
    </script>
    
    <template>
      <EventBack @click="handleEventBack(100, 'test', $event)" />
    </template>
    
    <style lang="scss">
    </style>
    
    1. <EventBack @click="handleEventBack(100, 'test', $event)" /> 利用$event可以取得點擊的所有事件
    2. 前面可以接一堆參數,$event一定要放在最後面
    3. 收到時,$event 就有包含所有資訊
    4. $event.target 就是點擊的實體本身
  2. 子元件:@/components/EventBack.vue
    <script>
    export default {
      setup() {
      },
    };
    </script>
    
    <template>
      <a href="javascript:;">點我</a>
    </template>
    
    <style></style>

     


:::

書籍目錄

展開 | 闔起

https%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D33%26tbdsn%3D1741

計數器

今天: 2884288428842884
昨天: 3755375537553755
總計: 4458723445872344587234458723445872344587234458723