diff --git a/pages/[slug].js b/pages/[slug].js index 99f49fed..cabde864 100644 --- a/pages/[slug].js +++ b/pages/[slug].js @@ -19,9 +19,9 @@ const Slug = props => { } // 文章锁🔐 - const [lock, setLock] = useState(true) + const [lock, setLock] = useState(post.password && post.password !== '') useEffect(() => { - if (post && post.password && post.password !== '') { + if (post.password && post.password !== '') { setLock(true) } else { setLock(false) diff --git a/pages/article/[slug].js b/pages/article/[slug].js index aba79897..09259f7f 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -35,9 +35,10 @@ const Slug = props => { } // 文章锁🔐 - const [lock, setLock] = useState(true) + const [lock, setLock] = useState(post.password && post.password !== '') + console.log('lock 默认值', lock) useEffect(() => { - if (post && post.password && post.password !== '') { + if (post.password && post.password !== '') { setLock(true) } else { setLock(false)