例如:http:// localhost:3000 /#/ report/123456
如何从Aurelia的网址中获取"123456"部分?
希望你能帮助我,在文档中找不到任何有用的东西.
小智 11
你可以在路由器的activate方法中获取提交的参数(在你的viewmodel中)
activate(params) {
return this.http.fetch('contacts/' + params.id)
.then(response => response.json())
.then(contact => this.contact = contact);
}
Run Code Online (Sandbox Code Playgroud)
在一个很好的博客中找到:http://www.elanderson.net/2015/10/aurelia-routing-with-a-parameter/
您必须为其定义一个路由:
{
route: ['report/:id'],
moduleId: './report',
title: 'Report',
name: 'report'
}
Run Code Online (Sandbox Code Playgroud)
然后在您的视图模型中,您可以id从params对象获取:
activate(params) {
console.log(params.id);
}
Run Code Online (Sandbox Code Playgroud)
小智 -8
var str = "http://localhost:3000/#/report/123456";
var res = str.split("/");
document.getElementById("demo").innerHTML = res[5];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4806 次 |
| 最近记录: |