vue.js - 无法将带有 vue 的计算机中的图像加载到 konva 层
问题描述
我正在尝试使用此vue-konva
解决方案将图像放在图层上。解决方案工作正常,从网络加载图像时,如示例中所示,但我无法将其更改为与我在.png
assets
根据我的文件夹结构,源应该是'../assets/image.png'
But it doesn't find it, ~/assets/image.png
or or @assets/image.png
or "require('../assets/image.png)"
.
(我曾经vue-cli
启动一个模板项目,并且正在使用调用的本地开发npm run dev
人员进行测试。我不确定这是否与路径问题有关,但我以前从未使用过这样的系统,所以它可能还好我所知)
解决方案
(致谢:解决方案是 matt_rothenberg#3118 在不和谐的 Vue Land 频道上发布的)。
这是一个沙箱
和代码:
<template>
<div>
<v-stage ref="stage" :config="configKonva">
<v-layer ref="layer">
<v-image :config="configBackground"></v-image>
</v-layer>
</v-stage>
</div>
</template>
<script>
const image = require("../assets/logo.png");
export default {
name: "HelloWorld",
data() {
return {
configKonva: {
width: 200,
height: 200
},
configBackground: {
x: 20,
y: 20,
image: new Image(),
width: 200,
height: 200
}
};
},
mounted() {
this.configBackground.image.src = image;
}
};
</script>
configBackground 被移动到data
而不是计算,并且图像通过require
.
推荐阅读
- mongodb - 在 mongodb 文档的嵌套数组中查找状态总和
- html - 表和绝对表,滚动不一样
- .htaccess - 重写一个被.htaccess美化的重写的url
- python - 如何读取存储在 Python Pandas 中本地的 ORC 文件?
- excel - 如何仅在存在时禁用数据透视项目?
- html - 元素(css)之间的缩进(边距,填充)
- python - 使用 https 配置 nginx 时,Python websocket 客户端引发“sslv3 alert bad record mac”错误
- c# - 从列表对象的列表字段中删除元素的最佳方法
- ios - 从 UITableViewCell 到 UITableViewCell 的条件转换总是成功
- ios - 在 iOS 上循环播放一段音频