Nuxtjs在IE11中报polyfill-eventsource added missing EventSource to window错误 解决方案

middleware中添加lru-cache导致

middleware中新建page-cache.js中间件,不知道是插件本身问题还是下面代码问题

解决问题:nuxt.config.js中移除serverMiddleware: [{ path: ‘/’, handler: ‘~/middleware/page-cache.js’ }],配置,
然后将下面代码全部注释掉,或者直接删掉page-cache.js文件

const LRU = require('lru-cache');
let cachePage = new LRU({
  max: 1000, // 缓存队列长度
  maxAge: 1 * 60 * 1000, // 缓存1分钟
});
export default function(req, res, next) {
  let url = req._parsedOriginalUrl;
  let pathname = url.pathname;
  // 通过路由判断,只有首页才进行缓存
  if (['/'].indexOf(pathname) > -1) {
    const existsHtml = cachePage.get('homeData');
    if (existsHtml) {
      return res.end(existsHtml.html, 'utf-8');
    } else {
      res.original_end = res.end;
      // 重写res.end
      res.end = function(data) {
        if (res.statusCode === 200) {
          // 设置缓存
          cachePage.set('homeData', { html: data });
        }
        // 最终返回结果
        res.original_end(data, 'utf-8');
      };
    }
  }
  next();
}

"@nuxtjs/axios"版本号问题

升级@nuxtjs/axios插件为@nuxtjs/[email protected]。IE11开始疯狂报上面错误,然后疯狂试错,差点崩溃,package.json改了n版,后来突然好了。以后再乱改乱升级package.json版本剁手。

问题解决开始排查问题:svn比较版本发现@nuxtjs/axios版本不一致,然后验证一下,将@nuxtjs/axios升级到5.9.0,开始报错,退回5.8.0问题解决。

总结

没事别瞎改package.json和升级插件。顺便附上package.json备用

{
  "name": "web",
  "version": "1.0.0",
  "description": "My smashing Nuxt.js project",
  "author": "",
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server --exec babel-node",
    "build": "nuxt build",
    "start": "cross-env NODE_ENV=production babel-node server/index.js",
    "generate": "nuxt generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "analyze": "nuxt build -a"
  },
  "dependencies": {
    "@nuxtjs/axios": "5.8.0",
    "axios-jsonp": "^1.0.4",
    "babel-plugin-component": "^1.1.1",
    "babel-preset-env": "^1.7.0",
    "cross-env": "^5.2.0",
    "element-ui": "^2.13.0",
    "koa": "^2.6.2",
    "koa-router": "^7.4.0",
    "lru-cache": "^5.1.1",
    "node-sass": "4.9.3",
    "nuxt": "^2.11.0",
    "sass": "^1.23.7",
    "sass-loader": "7.1.0",
    "vue-cookies": "^1.6.1"
  },
  "devDependencies": {
    "babel-cli": "6.26.0",
    "babel-loader": "^8.0.6",
    "file-loader": "^5.0.2",
    "nodemon": "^2.0.2",
    "url-loader": "^3.0.0"
  },
}

你可能感兴趣的:(Vue)