[英]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.