简体   繁体   中英

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

You are destructuring two fields assigning them the name title so you get the clash there. 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'})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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