内容简介:几种应用:这种是JQuery的.明显不是想要的,略过这种用classname找的方法.好像也不行.
几种应用:
这种是JQuery的.明显不是想要的,略过
这种用classname找的方法.好像也不行.
这种有点不明白.看起来也不是想要的.
最后这个才像是需要的.
封装
/**
* 简单生成条形码
* {
* width: 2,//较细处条形码的宽度
* height: 100, //条形码的宽度,无高度直接设置项,由位数决定,可以通过CSS去调整,见下
* quite: 10,
* format: "CODE128",
* displayValue: false,//是否在条形码下方显示文字
* font:"monospace",
* textAlign:"center",
* fontSize: 12,
* backgroundColor:"",
* lineColor:"#000"//条形码颜色
* }
*/
class SimpleBarcode extends Component {
componentDidMount() {
this.createBarcode();
}
componentWillReceiveProps(nextProps) {
if (this.props !== nextProps) {
this.createBarcode();
}
}
createBarcode = () => {
if (!this.barcode) return;
const {
width = 1, height = 35, margin = 0, label, displayValue = true,
} = this.props;
if (!label) {
return;
}
Barcode(this.barcode, label, {
displayValue, // 是否由Barcode显示二维码下面的值
width, // 每条线的宽度
height, // 高度
margin, //边距
});
};
render() {
const {
labelClassName, label, labelStyle, className, style, displayValue = true,
} = this.props;
return (
<div className={className} style={style}>
<svg
ref={(ref) => {
this.barcode = ref;
}}
/>
{displayValue ? null : <p className={labelClassName} style={labelStyle}>{label}</p>} // 自定义样式的值显示
</div>
);
}
}
复制代码
期待你的评论,点赞
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- RecyclerView使用指南(一)—— 基本使用
- 如何使用Meteorjs使用URL参数
- 使用 defer 还是不使用 defer?
- 使用 Typescript 加强 Vuex 使用体验
- [译] 何时使用 Rust?何时使用 Go?
- UDP协议的正确使用场合(谨慎使用)
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
JavaScript设计模式
Ross Harmes、Dustin Diaz / 谢廷晟 / 人民邮电出版社 / 2008 / 45.00元
本书共有两部分。第一部分给出了实现具体设计模式所需要的面向对象特性的基础知识,主要包括接口、封装和信息隐藏、继承、单体模式等内容。第二部分则专注于各种具体的设计模式及其在JavaScript语言中的应用,主要介绍了工厂模式、桥接模式、组合模式、门面模式等几种常见的模式。为了让每一章中的示例都尽可能地贴近实际应用,书中同时列举了一些JavaScript 程序员最常见的任务,然后运用设计模式使其解决方......一起来看看 《JavaScript设计模式》 这本书的介绍吧!