0
如何使用Polymer在文档的<head>
标签内绑定数据?如何使用Polymer在文档的<head>内绑定数据?
我问这个,因为页面信息如<title>
需要改变,这取决于用户浏览的页面,我想通过编写<title>{{title}}</title>
来保持与框架的其余部分保持一致。
由于
如何使用Polymer在文档的<head>
标签内绑定数据?如何使用Polymer在文档的<head>内绑定数据?
我问这个,因为页面信息如<title>
需要改变,这取决于用户浏览的页面,我想通过编写<title>{{title}}</title>
来保持与框架的其余部分保持一致。
由于
我怀疑其不可能的,因为对于数据结合工作,所述元件(或与所述的textContent元件)需要已经从聚合物,这当然head
或title
不是继承。
你可以做的是创建一个放置在主体中的元素(<proxy-title>
?),并且在观察者中以编程方式在dom中定位标题元素并写入它拥有的标题属性。
喜欢的东西
<dom-module id="proxy-title">
<template>
<style>
:host {
display:none;
};
</style>
</template>
<script>
Polymer({
is: 'proxy-title',
properties: {
title: {
type: String,
value: '',
observer: '_titleChanged'
}
},
_titleChanged: function(title) {
document.title = this.title;
}
});
</script>
</dom-module>
你会使用它,像这样
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<!-- other head stuff -->
</head>
<body>
<proxy-title title="[[someTitle]]"></proxy-title>
<!-- ... other stuff here -->
</body>
</html>
谢谢akc42。将测试这一次回家! – willsquire