【发布时间】:2019-05-08 14:53:42
【问题描述】:
当我尝试运行 NPM RUN generate 时出现错误,因为我在 nuxtServerInit 中使用 req 来获取 cookie。我该如何解决这个问题?
nuxtServerInit({ commit }, { req }) {
let auth = null
if(req) {
if (req.headers && req.headers.cookie) {
const parsed = cookieparser.parse(req.headers.cookie)
try {
auth = JSON.parse(parsed.auth)
} catch (err) {
// No valid cookie found
}
}
}
commit('SET_USER', auth)
},
【问题讨论】: