[英]How to destructure nested props from object in pug mixin?
所以我想建立哈巴狗混合:
mixin productTile({img, title, desc, price, withCatLink = false, cat: {title = '', path = ''} = {}})
.ProductTile
p
+icon({name: 'long-arrow-right'})
我这样称呼它:
-
const prodInfo = {
img: '/img/icon.png',
title: 'test title',
desc: 'testdesc',
price: '1200',
withCatLink: true,
cat: {
title: 'test category',
path: ''
}
};
+productTile(prodInfo)
但我面临的问题是:
SyntaxError: Argument name clash (366:103)
所以也许我对 object 道具解构有误,因为当我从 mixin 声明中删除cat: {title = '', path = ''} = {}
时一切正常
您正在解构两个字段,为它们分配名称title
,以便在那里发生冲突。 解构时只需重命名其中一个。 例如:
mixin productTile({img, title, desc, price, withCatLink = false, cat: {title: catalogTitle = '', path = ''} = {}})
.ProductTile
p
+icon({name: 'long-arrow-right'})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.