根据Vaadin 提供的文档和演示,路由参数应该绑定到 location.params。提供的示例使用聚合物,当我使用 LitElement 时,location.params 未定义。除了使用 JavaScript 结合 Lit 来解析 url 以提取使用的 url :parameter 之外,还有其他技巧吗?
我尝试通过编写基于 TS 的 Lit Elements 来进入 TypeScript,重构我的一个非常小的项目。
然而,它开始变得令人沮丧,因为我看不出这段代码有什么问题,因为它已简化为几乎与 HelloWorld 示例相同,但仍然给出错误:
import { LitElement, css, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
@customElement('student-ids')
export class StudentIds extends LitElement {
@property()
name = 'Somebody';
render() {
return html`
<h1>Classroom Ids</h1>
<p>Hello, ${this.name}!</p>
`;
}
}
Run Code Online (Sandbox Code Playgroud)
在 Chrome 中我收到错误:
Uncaught (in promise) Error: The following properties on element student-ids will not trigger updates
as expected because they are set using class fields: name. Native class fields and some compiled …Run Code Online (Sandbox Code Playgroud)