lit 在以下 URL 中介绍了“更改检测”的示例。 https://lit.dev/playground/#sample=examples/properties-has-changed
为什么有一个“。” 在 my-element.ts 的第 16 行中指定“日期显示”选项时,在“日期”的开头?
import { LitElement, html} from "lit";
import {customElement, property} from 'lit/decorators.js';
import {localDateFromUTC} from './date-utils.js';
import './date-display.js';
@customElement('my-element')
class MyElement extends LitElement {
@property() date?: Date;
render() {
return html`
<p>Choose a date:
<input type="date" @change=${this._dateChanged}></p>
<p><button @click=${this._chooseToday}>Choose Today</button></p>
<p>Date chosen: <date-display .date=${this.date}></date-display></p>
`;
}
_dateChanged(e: Event) {
const utcDate = (e.target as HTMLInputElement).valueAsDate;
if (utcDate) {
this.date = localDateFromUTC(utcDate);
}
}
_chooseToday() {
this.date = new Date();
}
}