search

Home  >  Q&A  >  body text

laravel - vuejs local image preview, how to get the image src?

vuejs local image preview, how to get the image src?

ComponentImagePreview.vue

<template>
    <p class="card text-center" style="width: 16rem;">
        <img class="card-img" :src="imgDataUrl" style="height: 16rem;">
        <p class="card-footer text-muted">
            <input type="file" id="image" name="image" @change="preview($event)">
        </p>
    </p>
</template>

<script>
    export default {
        data(){
            return {
                imgDataUrl: ''
            }
        },
        methods: {
            preview(event){
                this.imgDataUrl = event.target.files;
            }
        }
    }
</script>

Problem:
After clicking a picture, the picture cannot be displayed. src="[object File]" is displayed in the browser debugging window. How should I write it? Can?
The following two ways of writing in the preview method will not work.

event.target.files
event.target.files[0]
滿天的星座滿天的星座2797 days ago691

reply all(2)I'll reply

  • 为情所困

    为情所困2017-05-16 16:48:32

    event.target.value this is src

    reply
    0
  • 阿神

    阿神2017-05-16 16:48:32

    console.log(event.target.files) to see what the structure is like

    reply
    0
  • Cancelreply