vue-barcode
vue-barcode copied to clipboard
How to control the width of SVG?
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.
have you solved it?
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
Css: transform: scale(.7);
It seems late but hope can help others.