Vue.jsでファイルピッカーを開発しています。選択したファイルのプレビューを表示したい。 私はこれを達成するためにFileReaderAPIを使用します。私はFileReader
オブジェクトのreadAsDataURL
メソッドでデータURLとしてユーザーが選択したファイルを読んでいます。Vue.jsコンポーネントメソッド内でFileReader APIを使用する
私はreader.onload
は次のように関数ではないというエラーメッセージを取得しかし:それは読者が私は上記しているFileReaderの未定義エラー以下、定義されていないことがあり
Uncaught TypeError: reader.onload is not a function
at VueComponent.handleFileChanges
を。次のように私はこれを行うやろうどのよう
は次のとおりです。
handleFileChanges (e) {
var reader = new window.FileReader() // if window is not used it says File READER is not defined
reader.onload(function (event) {
// dispatch fileAttached to state UI postEditor with event.target.result as read dataURL
let imageDataURL = event.target.result
this.$store.dispatch('attachedFile', imageDataURL) // or previewFile
})
reader.readAsDataURL(e.target.files[i])
}
私が行方不明ですポイントは何ですか?