I want to handle the cancel press when uploading a file
I looked at some examples that were implemented using pure JavaScript here is an example
All these examples work fine, I tried to implement this example using Vue JS, but it does not work correctly for me
<div>
<label for="upload" @click="initialize">Upload File</label>
<input type="file" id="upload" ref="theFile" hidden />
</div>
<script>
export default {
methods: {
initialize() {
document.body.onfocus = this.checkIt;
alert("initializing");
},
checkIt() {
if (this.$refs.theFile.value.length) alert("Files Loaded");
else alert("Cancel clicked");
document.body.onfocus = null;
alert("checked");
},
},
};
</script>
You can see an example of my code in codesandbox