简体   繁体   中英

How to populate object props in pug mixin?

So i have this mixin:

mixin slider({classes: {slider, arrows, arrow, dots, dot}, useArrows = false, useDots = false, dotsCounter}, sliderSettings)
  div(class=['slider', slider].join(' '))
    .glide__track(data-glide-el="track")
      ul.glide__slides
        block
    if useArrows
      div(class=arrows, data-glide-el="controls")
        span(class=['arrow-left', arrow].join(' '), data-glide-dir="<<")
          +icon({name: 'angle-left'})
        span(class=['arrow-right', arrow].join(' '), data-glide-dir=">>")
          +icon({name: 'angle-right'})
    if useDots
      div(class=['slider-dots', dots].join(' '), data-glide-el="controls[nav]")
        while i < dotsCounter
          span(class=['slider-dot', dot].join(' '), data-glide-dir="=" + i++)

  script new Glide('.#{slider}', #{sliderSettings}).mount()

As a second param of my mixin i'm passing sliderSettings, that is an object with props, that i need to pas in script tag at the end of the code. If i'm using #{sliderSettings} , i'm getting [object Object] in html code of the page, but i need to get populated object with it's props.

Is it possible to get what i want?

So i found an answer. I need to improve this line:

script new Glide('.#{slider}', #{sliderSettings}).mount()

to this:

script new Glide('.#{slider}', !{JSON.stringify(sliderSettings)}).mount()

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