[英]Vuejs : How to display uploaded image in child component
I use v-file-input of vutify to upload the image so I have:我使用 vutify 的 v-file-input 来上传图像,所以我有:
<v-file-input
label="Image"
filled
accept="image/png, image/jpeg, image/bmp"
prepend-icon="mdi-camera"
v-model="image"
></v-file-input>
Where I console.log the v-model image I get a File object like That:在我控制台记录 v-model 图像的地方,我得到了一个文件 object,如下所示:
File {name: "img.png", lastModified: 1588256009000, lastModifiedDate: Thu Apr 30 2020, webkitRelativePath: "", size: 53258, …}
name: "img.png"
lastModified: 1588256008000
lastModifiedDate: Thu Apr {}
webkitRelativePath: ""
size: 53259
type: "image/png"
....
So how can I display it into the component or another child component from this Object?那么如何将它显示到此 Object 的组件或另一个子组件中?
Create a computed property of imageUrl
that returns the value of URL.createObjectURL(image)
and then you can use imageUrl
in the same component or pass it off as a prop to a child component :创建imageUrl
的计算属性,该属性返回URL.createObjectURL(image)
的值,然后您可以在同一组件中使用imageUrl
或将其作为道具传递给子组件:
computed: {
imageUrl() {
return this.image ? URL.createObjectURL(this.image) : "";
}
}
Use the imageUrl
as:使用imageUrl
作为:
<img :src="imageUrl" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.