Javascript 使用公共访问器lwc子组件声明字段public vs private

Javascript 使用公共访问器lwc子组件声明字段public vs private,javascript,salesforce,salesforce-lightning,lwc,Javascript,Salesforce,Salesforce Lightning,Lwc,我需要将一个参数从父组件传递给lwc中的子组件。将字段设置为公共字段与使用公共访问器设置为私有字段之间有区别吗 // Private field with public getter import { LightningElement, api, track } from 'lwc'; export default class TodoItem extends LightningElement { @track _itemName = 'New Item'; @a

我需要将一个参数从父组件传递给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;
    }
}
vs


在LWC中,建议采用:

//公共访问器
从“lwc”导入{LightningElement,api};
将默认类导出到DoItem扩展LightningElement{
@原料药
itemName='新项目'
}
附言:赛道装饰师现在正在工作

就像20年春天的所有油田一样,它们是被动的

//Public accessor
import { LightningElement, api, track } from 'lwc';

export default class TodoItem extends LightningElement {
    @api 
    _itemName = 'New Item'; 
}