0👍
try this:
-
First create the variable.
var photo = ref();
-
bind to input file tag
<input
id="photo"
type="file"
name="photo"
hidden
@change="previewImage"
@input="photo= $event.target.files[0]"
/> -
This is the upload function
const uploadImg = () => {
var formData = new FormData();
formData.append("photo", photo);(async () => {
await axios
.post(route("editImg"), formData, {
headers: {
Accept: "application/json",
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "multipart/form-data",
},
credentials: "same-origin",
})
.then((response) => {
console.log(response);.catch((e) => { console.log("err = ", e); });
})();
};
- [Vuejs]-How to bind slot with v-bind for url attribute?
- [Vuejs]-Where I have error when convert vue js code to one html file?
Source:stackexchange.com