Skip to content

Commit 1b864c0

Browse files
committed
update
1 parent c23f2dc commit 1b864c0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
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": "1.0.5",
3+
"version": "1.0.5-beta1",
44
"description": "a react verification code component",
55
"main": "dist/index.js",
66
"files": [

src/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,14 @@ export default class Vcode extends React.PureComponent<Props, State> {
262262
* */
263263
onDraw(value: string | undefined) {
264264
let c = ""; // 存储生成的code
265-
const div = document.getElementById(this.state.id) as HTMLElement;
265+
const div = document.getElementById(this.state.id);
266+
266267
const isImg: boolean = /^http[s]*:\/\/|\.jpg$|\.png$|\.jpeg$|\.gif$|\.bmp$|\.webp$|^data:image/.test(
267268
value || ""
268269
); // 是否是图片
269-
div.innerHTML = "";
270+
if (div) {
271+
div.innerHTML = "";
272+
}
270273

271274
if (isImg) {
272275
// 用户传递了一张图片
@@ -277,7 +280,7 @@ export default class Vcode extends React.PureComponent<Props, State> {
277280
"max-height:100%",
278281
].join(";");
279282
dom.src = value as string;
280-
div.appendChild(dom);
283+
div && div.appendChild(dom);
281284
this.props.onChange && this.props.onChange(null);
282285
return null;
283286
}
@@ -296,14 +299,14 @@ export default class Vcode extends React.PureComponent<Props, State> {
296299
];
297300
dom.innerHTML = String(temp);
298301
c = `${c}${temp}`;
299-
div.appendChild(dom);
302+
div && div.appendChild(dom);
300303
}
301304

302305
// 生成好看的线条
303306
for (let i = 0; i < this.state.options.lines; i++) {
304307
const dom = document.createElement("div");
305308
dom.style.cssText = this.lineCss();
306-
div.appendChild(dom);
309+
div && div.appendChild(dom);
307310
}
308311
this.props.onChange && this.props.onChange(c); // 触发回调
309312
return c;

0 commit comments

Comments
 (0)