从 Vue.js 移植到 Nuxt.js 时出现错误。
我正在尝试vue-session在node_modules. 它编译成功,但在浏览器中我看到错误:
未定义 ReferenceError 窗口
node_modules\vue-session\index.js:
VueSession.install = function(Vue, options) {
if (options && 'persist' in options && options.persist) STORAGE = window.localStorage;
else STORAGE = window.sessionStorage;
Vue.prototype.$session = {
flash: {
parent: function() {
return Vue.prototype.$session;
},Run Code Online (Sandbox Code Playgroud)
所以,我遵循了这个文档:
rewardadd.vue:
import VueSession from 'vue-session';
Vue.use(VueSession);
if (process.client) {
require('vue-session');
}Run Code Online (Sandbox Code Playgroud)
nuxt.config.js:
build: {
vendor: ['vue-session'],Run Code Online (Sandbox Code Playgroud)
但我仍然无法解决这个问题。