我需要将参数从父组件传递给 lwc 中的子组件。使用公共访问器将字段设为公共与私有之间有区别吗?
// Private field with public getter
import { LightningElement, api, track } from 'lwc';
export default class TodoItem extends LightningElement {
@track
_itemName = 'New Item';
@api
get itemName() {
return this._itemName;
}
set itemName(value) {
this._itemName = value;
}
}
对比
//Public accessor
import { LightningElement, api, track } from 'lwc';
export default class TodoItem extends LightningElement {
@api
_itemName = 'New Item';
}