服务端和客户端身份校验
#27440
Replies: 4 comments
-
建议用 |
Beta Was this translation helpful? Give feedback.
0 replies
-
好的非常感谢!! |
Beta Was this translation helpful? Give feedback.
0 replies
-
你需要理解,nuxt默认是SSR模式 ,也就是服务端渲染,服务端环境是没有localStorage(这个东西只在浏览器环境中有)。也就是说,你只需要在非SSR期间,就能使用。在setup语法糖中,setup钩子是服务端渲染,也就是说,如果你这么写:
这样就会报错
你在触发表单时,就能使用 |
Beta Was this translation helpful? Give feedback.
0 replies
-
国内的人用的比较少呢。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
最近使用 Nuxt 打算做一个 blog,
在用户请求登录后,服务端将返回一个
token
,我将这个token存储在了localStorage
使用户在下次访问不用再次登录了.但是在使用
localStorge.setItem('token', '...')
时,报错localStorge
未定义替换使用 vueuse 的 useLocalStorage('token', '') 可以正常把token存储在 localStorage, 但是当我刷新浏览器后存储的
token
却被自动替换 成了''
,是否有别的方案可以进行身份校验,或者阻止 token 值被覆盖。
Beta Was this translation helpful? Give feedback.
All reactions