简体   繁体   English

如何在 pug mixin 中解构 object 中的嵌套道具?

[英]How to destructure nested props from object in pug mixin?

So i want to build pug mixin:所以我想建立哈巴狗混合:

mixin productTile({img, title, desc, price, withCatLink = false, cat: {title = '', path = ''} = {}})
  .ProductTile
    p
      +icon({name: 'long-arrow-right'})

I'm calling it like that:我这样称呼它:

-
  const prodInfo = {
    img: '/img/icon.png',
    title: 'test title',
    desc: 'testdesc',
    price: '1200',
    withCatLink: true,
    cat: {
      title: 'test category',
      path: ''
    }
  };

+productTile(prodInfo)

But i'm facing with the problem:但我面临的问题是:

SyntaxError: Argument name clash (366:103)

So maybe i'm wrong with object prop desctructuring, cause when i'm removing cat: {title = '', path = ''} = {} from mixin declaration there is everything ok所以也许我对 object 道具解构有误,因为当我从 mixin 声明中删除cat: {title = '', path = ''} = {}时一切正常

You are destructuring two fields assigning them the name title so you get the clash there.您正在解构两个字段,为它们分配名称title ,以便在那里发生冲突。 Just rename one of them when destructuring.解构时只需重命名其中一个。 For example:例如:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM