将其嵌套在 Stencil.js 个组件中
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>;
}
但我总是重复自己写一个嵌套的 this 变量,如上所示。
有没有更优雅的方式来满足我的需求?
使用箭头函数:
render() {
return <Host>
{this.images ?
this.imagesArray.map((el) => (<img
// @ts-ignore
src={this.imageSize || el.url}/>
)) : <slot/>}
</div>
</Host>;
}
我想知道是否有更简单的方法在 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>;
}
但我总是重复自己写一个嵌套的 this 变量,如上所示。
有没有更优雅的方式来满足我的需求?
使用箭头函数:
render() {
return <Host>
{this.images ?
this.imagesArray.map((el) => (<img
// @ts-ignore
src={this.imageSize || el.url}/>
)) : <slot/>}
</div>
</Host>;
}