File inputs are read only. Use a v-on:change listener instead.
时间: 2024-04-09 11:29:23 浏览: 7
For handling file inputs in Vue.js, you can use the `v-on:change` directive to listen for changes in the input field. Here's an example:
```html
<template>
<div>
<input type="file" @change="handleFileChange" />
</div>
</template>
<script>
export default {
methods: {
handleFileChange(event) {
const file = event.target.files[0];
// Do something with the file
},
},
};
</script>
```
In this example, the `handleFileChange` method is triggered when the user selects a file. You can access the selected file using `event.target.files[0]` and perform any necessary actions with it. Remember that file inputs are read-only, so you won't be able to directly modify the file on the client side.