提交 5758ba0c authored 作者: 钟是志's avatar 钟是志

优化代码

上级 fd8f5bff
...@@ -8,7 +8,12 @@ export const ImgViewer = props => { ...@@ -8,7 +8,12 @@ export const ImgViewer = props => {
if (props.images && Array.isArray(props.images)) { if (props.images && Array.isArray(props.images)) {
return props.images.filter(i => checkIsImage(i.src)); return props.images.filter(i => checkIsImage(i.src));
} else { } else {
return [path]; return [
{
src: path,
alt: '预览',
},
];
} }
}, [props.images]); }, [props.images]);
const activeIndex = useMemo(() => { const activeIndex = useMemo(() => {
...@@ -17,9 +22,5 @@ export const ImgViewer = props => { ...@@ -17,9 +22,5 @@ export const ImgViewer = props => {
} }
return 0; return 0;
}, [path]); }, [path]);
return <Viewer visible={true} return <Viewer visible={true} onClose={onClose} activeIndex={activeIndex} images={images} />;
onClose={onClose}
activeIndex={activeIndex}
images={images}
/>;
}; };
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论