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>