Retrieve e.target.files in another method in Vue2
Clash Royale CLAN TAG#URR8PPP
Retrieve e.target.files in another method in Vue2
I'm new to Vue.
How can I access e.target.files
from submit()
?
Tried refs - this.$refs.myFileInput.value
but it not gives me FileListFile(17050)...
object.
e.target.files
submit()
this.$refs.myFileInput.value
FileListFile(17050)...
console.log(e.target.files[0])
in imageChanged(e)
gives what I need: File(17050) name: "hello.jpg", size: 17050, ...
console.log(e.target.files[0])
imageChanged(e)
File(17050) name: "hello.jpg", size: 17050, ...
Now the code:
imageChanged (e)
console.log(e.target.files[0])
let files = e.target.files
for (var i = files.length - 1; i >= 0; i--)
let fileReader = new FileReader()
fileReader.readAsDataURL(files[i])
fileReader.onload = (e) =>
this.attachedFile.allData.push(file: e.target.result, size: files[i].size, type: files[i].type, inputnameispreview: this.picked, webtemplateid: this.$route.params.id, filename: files[i].name)
,
submit () {
let self = this
api.post('http:..', this.attachedFile)...
1 Answer
1
Hope you have set ref like this
<input type="file" id="file" ref="myInputFile" class="">
In Js you can access file like this
this.$refs.myInputFile.files
Instead of
this.$refs.myInputFile.value
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thx. I'll try at monday)
– Vit
Aug 11 at 15:04