P粉0020233262023-09-02 19:15:13
preventDefault is useful in the following situations:
To disable the button in your case you can use:
const warn = (msg,DOMEvent) => { DOMEvent.srcElement.disabled = true; }
P粉7262346482023-09-02 17:59:20
preventDefault()
will not disable the button, but will prevent its default action, which will be mainly noticed in the Submit
action.
To disable a button on click, you need to do something like this:
<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>