[英]Nested this in Stencil.js components
我想知道是否有更簡單的方法可以在 Stencil.js 組件中使用嵌套的“this”。
目前我正在這樣做:
render() {
let thisNested = this;
return <Host>
{this.images ?
this.imagesArray.map(function (el) {
return <img
// @ts-ignore
src={thisNested.imageSize ? thisNested.imageSize : el.url}/>
}) : <slot/>}
</div>
</Host>;
}
但是我總是重復自己寫一個嵌套的這個變量,如上所示。
有沒有更優雅的方式來做我需要的事情?
使用箭頭 function:
render() { return <Host> {this.images? this.imagesArray.map((el) => (<img // @ts-ignore src={this.imageSize || el.url}/> )): <slot/>} </div> </Host>; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.