1024Web前端之路Vue.js

8、Vue3事件绑定

2022-07-11  本文已影响0人  圆梦人生

案例

<template>
  <div @click="parentclick">
    <div @click.stop="subclick">子元素点击</div>
  </div>
   <div @click.once="subclick2">子元素点击2</div>
   <br>
   <input type="text" @keyup.enter="enterfun">
</template>

<script>
export default {
    setup(){
        let parentclick = ()=>{
            alert(2)
        }
        let subclick = ()=>{
            alert(1);
        }
        let subclick2 = ()=>{
            alert(3);
        }
        let enterfun = ()=>{
            alert('回车')
        }
        let onClick = ()=>{
            alert('任意键');
        }
        return {
            onClick,
            enterfun,
            parentclick,
            subclick,
            subclick2
        }
    }
}
</script>
上一篇下一篇

猜你喜欢

热点阅读