Skip to content

Commit 872b2f1

Browse files
author
luo
committed
0.0.4 动态更新width和height后,生成的验证码不再错位
1 parent 961c1dc commit 872b2f1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-vcode",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "a react verification code component",
55
"main": "dist/index.js",
66
"scripts": {

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ class Vcode extends React.Component {
7575
}
7676

7777
/** 组件参数改变 **/
78-
componentWillReceiveProps(nextP) {
78+
componentWillReceiveProps(nextP, nextS) {
7979
if(this.props.value !== nextP.value) {
8080
this.onDraw(nextP.value);
8181
}
82+
if(this.props.width !== nextP.width || this.props.height !== nextP.height) {
83+
this.setState({
84+
width: nextP.width,
85+
height: nextP.height,
86+
});
87+
}
8288
}
8389

8490
/** 用户点击的验证码图片 **/
@@ -124,7 +130,6 @@ class Vcode extends React.Component {
124130
div.appendChild(dom);
125131
}
126132
} else {
127-
console.log('走这里');
128133
const uW = this.state.width / this.state.len; // 每个字符占的宽度
129134
for (let i = 0; i < this.state.len; i++) {
130135
const dom = document.createElement('span');

0 commit comments

Comments
 (0)