vue-barcode icon indicating copy to clipboard operation
vue-barcode copied to clipboard

How to control the width of SVG?

Open jo-narae opened this issue 6 years ago • 3 comments

Hello, lindell! The width option of the current vue-barcode is the width option of the bar. However, in addition to adjusting the barcode width, I need a way to control the width of the SVG.

I don't know how to control SVG width. I would thank it if you could tell me. Have a nice day. thank you.

jo-narae avatar Apr 13 '18 13:04 jo-narae

have you solved it?

jamesriady avatar Jul 27 '18 04:07 jamesriady

I try this to adjust the container's width, still not a neat solution

<vue-barcode ref="barcode" ... ></vue-barcode>
...
// in updated() or somewhere after jsbarcode rendered
const el = this.$refs.barcode.$el
const svg = el.getElementsByClassName('vue-barcode-element')[0]
const rect = svg.getElementsByTagName('rect')
const attr = rect[rect.length - 1].attributes
const width = Number(attr.x.value) + Number(attr.width.value)
el.style = `width: ${width}px;` // or max-width

tngmichael avatar May 22 '19 03:05 tngmichael

Css: transform: scale(.7);

It seems late but hope can help others.

seaklengfc avatar Jun 23 '21 08:06 seaklengfc