I trying to write a pretty uploader in Vue.js. I just hide <input type="file"> element and trigger click function while mdl-button is clicked.
Following code is my implementation.
template:
<form method="post" action="#" @submit.prevent="">
<input id="fileInput" type="file">
<mdl-button type="submit" @click="onClick" colored raised>
<span>Upload</span>
</mdl-button>
</form>
script:
export default {
data () {
return {
filePath: null
}
},
methods: {
onClick: function (e) {
document.getElementById('fileInput').click()
}
}
}
style:
#fileInput {
display: none;
}
We can notice that document.getElementById is not Vue-style.
How about binding fileInput's click function to mdl-button's click event?