When el-input
the component is disabled, its click
event will still be fired. This is because click
the event is a browser-level event, not el-input
controlled by the component. Even if the component is disabled, its elements still exist in the document and can be clicked by the mouse. If you wish to block click events while in the disabled state, consider using an @click
event listener to handle the event and return when the component is disabled false
. Here is sample code:
<template>
<el-input :disabled="isDisabled" @click="handleClick" />
</template>
<script>
export default {
data() {
return {
isDisabled: true,
};
},
methods: {
handleClick() {
if (this.isDisabled) {
return false;
}
// Handle click event
},
},
};
</script>
In this example :disabled
, el-input
the component is set to the disabled state using the property, and the click event is handled using @click
the event listener. In handleClick
the method , check isDisabled
that the property is true
. If so, returns false
to prevent the event's default behavior. If not, the default behavior for handling events.