这是我在HTML中的自定义标记,我希望{{value}}根据元素加载时的延迟进行更改。
<my-latency value={{value}}></my-state>
下面是我正在尝试编写的自定义元素,它会计算用户和服务器之间的延迟。但我不知道如何将延迟值(完美地将console.log完全恢复)恢复为自定义标记的值。
<link rel="import" href="../../bower_components/polymer/polymer.html">
<script>
Polymer({
is: "my-latency",
ready: function() {
socket = io('http://198.191.94.231:9000');
socket.emit('latency', Date.now(), function(startTime) {
var latency = Date.now() - startTime;
console.log(latency); // returns: 203
});
},
这是一切都开始出错......
properties: {
latency: number,
response: {
value: latency,
type: number,
reflectToAttribute: true,
readOnly: true,
notify: true
}
},
responseHandler: function(response) {
this.value = latency;
}
});
</script>
答案 0 :(得分:0)
看起来ready()
缺少this.value
var latency = Date.now() - startTime;
this.value = latency;