P粉0020233262023-09-02 19:15:13
preventDefault在以下情況下非常有用:
#在您的情況下停用按鈕,您可以使用:
const warn = (msg,DOMEvent) => { DOMEvent.srcElement.disabled = true; }
P粉7262346482023-09-02 17:59:20
preventDefault()
不會停用按鈕,但會阻止其預設操作,主要在Submit
操作中會注意到。
要在點擊時停用按鈕,你需要像這樣做:
<template> <div> <button :disabled="isDisabled" v-on:click="warn('msg',$event)">warn</button> </div> </template> <script> import {ref} from 'vue' export default { name: 'App', components: { HelloWorld } } </script> <script setup> const warn = (msg,DOMEvent) => { console.log("warn:",msg," event:",DOMEvent); //DOMEvent.preventDefault() //uncomment if needed this.isDisabled = true; } </script>