1、安装
npm install vue-barcode --save
2、在需要的页面引入注册和使用
<template>
<div>
<!--使用->
<img id="barcode"/>
<!--<svg id="barcode"></svg>->
</div>
</template>
<script>
//映入注册
import JsBarcode from 'jsbarcode'
export default {
name: 'JsBarcode',
props: {
content: String,
},
mounted(){
if(this.content != ""){
//实例化
JsBarcode("#barcode", this.content, {
format: "CODE39", //条形码的格式
// lineColor: "#0aa", //线条颜色
width:1, //线宽
height:40, //条码高度
// displayValue: false //是否显示文字信息
});
}
},
}
</script>
3、文档参考
https://github.com/lindell/vue-barcode
https://github.com/lindell/JsBarcode/wiki/Options