以下是我的聚合元素的代码。我已经尝试了正常的dom绑定,一切都很顺利。然而,img的src却不起作用。我在chrome开发工具中检查了html,显示的src都是错误的。这里的src说的是/img/12.jpg,这意味着图像在html文件所在的文件夹中,但它实际上指的是文件夹的根目录。我期望在开发工具中看到的src是 http://localhost:3000/elements/image-hover/img/12.jpg,但实际上是img/12.jpg。除了将其硬编码为预期的src之外,我能做什么?
编辑:我通过使用Polymer提供的content标签解决了这个问题。
这个问题仍然存在,我如何找到该元素所在文件夹的来源。
<dom-module id="image-hover">
<template>
<img src="{{imgsrc}}"/>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'image-hover',
properties: {
imgsrc: {
type: String,
value: 'img/12.jpg'
}
}
});
})();
</script>
编辑:我通过使用Polymer提供的content标签解决了这个问题。
<content id="image" select="img"></content>
这个问题仍然存在,我如何找到该元素所在文件夹的来源。
value: function () { return "/image/12.jpg"; }
- Ben Thomas