我想做一个单页应用程序。当我转到类似路径时localhost/person-info/101
,如何使用 page.js 将 URL 参数获取到 Polymer 元素中?
在使用更改页面之前,我必须使用这些参数来选择或更改person-info
元素中的数据neon-animated-page
内容app.js
:
window.addEventListener('WebComponentsReady', function () {
var app = document.querySelector('#app');
page('/', home);
page('/person-info/:user', showPersonInfo);
page({
hashbang: true
});
function home() {
app.route = 'index';
console.log("app route" + app.route);
console.log("home");
}
function showPersonInfo(data) {
console.log(data);
console.log(data.params.user);
app.params = data.params;
app.route = 'person-info';
}
});
还有我的聚合物元素person-info.html
<link rel="import" href="bower_components/iron-list/iron-list.html">
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/paper-toolbar/paper-toolbar.html">
<link rel="import" href="bower_components/paper-icon-button/paper-icon-button.html">
<script type="text/javascript" src="bower_components/jquery-2.1.4.min/index.js"></script>
<script src="js/app.js"></script>
<dom-module id="person-info">
<style>
:host {
display: block;
font-family: sans-serif;
@apply(--layout-fit);
@apply(--layout-vertical);
}
.toolbar {
background: #3f78e3;
}
a {
color:#FFF;
}
</style>
<template id="person-info">
<paper-toolbar class="toolbar">
<a href="/">
<paper-icon-button icon="icons:arrow-back"></paper-icon-button>
</a>
<div>test</div>
<div>test</div>
</paper-toolbar>
<content></content>
</template>
<script>
Polymer({
is: 'person-info',
ready: function () {
console.log("person-info page");
this.testdd = "adisak";
console.log("user ---->"+this.params);
console.log(this);
},
properties: {
dataindex: String
}
});
</script>
</dom-module>