vue3 CompositionAPI を使って選択した画像情報を取得するコード、以下を書いたのですが、画像情報が取得できません。
<template>
<input type="file" name="image" accept="image/*" ref="selectImage"@change="previewImage"/>
</template>
<script>
import { ref,selectImage} from "vue";
setup() {
const selectImage = ref();
let previewImage = () =>{
let file = selectImage.value; //ファイル情報の取得
(省略)
};
return {
previewImage,
selectImage,
}
</script>
concole.log(file)で変数の中身を確認したところ、以下のHTML要素が取得され、画像の情報が取得できていません。
<input id="img" type="file" name="image" accept="image/*">
以下のコードで選択画像の取得ができると思っていたのですが、実際の挙動はHTML要素を取得していました。。。。
let file = selectImage.value; //ファイル情報の取得
optionAPIで書いていた時は以下のコードで選択画像の情報が取得できていました。
previewImage:function(){
let file = this.$refs.selectImage.files; //ファイル情報の取得
CompositionAPIでは this.$refs
を使わなくなりました。という記述をみて、書き方を変えたのですが、思っている挙動になりません。
どうすれば選択画像の情報を取得できるでしょうか?