vue.js - 如何从 vue 函数将图像设置为 vue-picture-input
问题描述
在 vue 中,我们可以使用 vue 函数设置输入字段的值v-model
。例如:
<form id="demo">
<!-- text -->
<p>
<input type="text" v-model="msg">
{{msg}}
</p>
</form>
new Vue({
el: '#demo',
data: {
msg : 'hi!'
}
})
然后,我们将hi!
在输入字段中有值。但是,我们如何在vue-picture-input中做同样的事情呢?它没有v-model。在更新模型之前,我需要vue-picture-input
先将图像设置为预览图像。我尝试添加prefill
,但更新模型后,控制台中显示错误:net::ERR_EMPTY_RESPONSE
.
解决方案
vue-picture-input
有一个名为 prefill 的道具。您可以使用预填充来加载预加载图像。尽管在这里使用v-model
,您需要将prefill
道具与imageURL
. 看看下面的演示。
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-picture-input"></script>
<title>In the browser!</title>
</head>
<body>
<div id="app">
<p>{{ message }}</p>
<picture-input width="200"
height="200" :prefill="imgURL"></picture-input>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
imgURL: "https://picsum.photos/200/200",
},
components: {
'picture-input': PictureInput
}
})
</script>
</body>
</html>
推荐阅读
- typescript - 如何将 Shoelace 组件库添加到现有的 Stencil.js 项目
- java - Spring Boot @Valid 不给出错误消息或有错误始终设置为 False
- laravel - Laravel8中未显示多个关键字搜索sql语句
- api - 如何以编程方式发现 ASP.NET Core 应用程序中的所有 API url
- unreal-engine4 - 我想安装 Vulkan 以使用 UnrealEnginge 和 Carla 模拟器
- c - 无法将“&L”从“列表*”转换为“列表”
- javascript - Jenkins 没有为 webdriverio 自动化套件发布 HTML 报告
- c# - 为什么 return true 或 false 会中断;不工作?
- java - Java/Groovy/Gradle:如何更改 jar 名称(但不是 artifact-id)以进行发布?
- python - 如何在不使用 explode_outer 维护 NULL 数据点的情况下扁平化 PySpark 2.1.1 模式?