【问题标题】:I'm using nuxt.js An error occurred in ie11我在用nuxt.js ie11出现错误
【发布时间】:2019-09-01 15:09:52
【问题描述】:

我现在正在使用 nuxt.js。 但是在ie11中出现了一些错误。

首先我使用的是 vuetify 和 nuxt.js SSR(pwa) 模式。

IE11出现如下错误。

这是我的错误 https://i.imgur.com/mpkuXyN.png

我使用以下模块。

import Cookies from 'universal-cookie'
import CookieParser from 'cookieparser'

还有我的一些代码 我是新手开发者,代码可能很奇怪。

auth middleware
 export default function ({ store, redirect, error }) {
   if (!store.state.auth || store.state.error) {
     return redirect('/login')
   }
 }
login.vue [The part that uses cookies]

  methods: {
    async Login (email, password) {
      await this.$store.dispatch('obtainToken', { email: email, password: password })
        .then((response) => {
          // login success
          let cookies = new Cookies()
          let jwt = cookies.get('jwt')
          if (jwt) {
            this.$router.push(this.$route.query.redirect || '/')
          } else {
            this.login_false = true
          }
        })
     }
  }
index.vue [The part that uses cookies]

  async asyncData ({ req, store, params, context }, callback) {
    let cookies = new Cookies()
    let jwt = cookies.get('jwt')
    if (jwt) {
      let [mainData] = await Promise.all([
        axios.get('/api/profile/view', { headers: { Authorization: `Bearer ${jwt}` } })
      ])
      store.dispatch('setuserData', mainData.data)
      callback(null, { data: mainData.data })
    } else {
      let cookies = CookieParser.parse(req.headers.cookie)
      let jwt = cookies.jwt
      let [mainData] = await Promise.all([
        axios.get('/api/profile/view', { headers: { Authorization: `Bearer ${jwt}` } })
      ])
      store.dispatch('setuserData', mainData.data)
      callback(null, { data: mainData.data })
    }
  },
nuxt.config.js

  build: {
    analyze: {
      analyzerMode: 'static'
    },
    plugins: [
      new webpack.ProvidePlugin({
        '$': 'jquery',
        jQuery: 'jquery'
      })
    ],
    extractCSS: true,
    watch:['api'],
    vendor:['babel-polyfill', '@johmun/vue-tags-input'],
    extend (config, ctx) {
      // Run ESLint on save
      if (ctx.isDev && ctx.isClient && process.env.NODE_ENV !== 'production') {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/,
          options: {
            fix: true
          }
        })
      }
      if (ctx.isServer) {
        config.externals = [
          nodeExternals({
            whitelist: [/^vuetify/]
          })
        ]
      }
    }
  },

我的代码有什么问题?还是这是一个模块问题? 请帮帮我!

【问题讨论】:

    标签: internet-explorer cookies nuxt.js


    【解决方案1】:

    我尝试检查您的代码和错误消息。

    我发现您在代码中使用了 "=>" 箭头函数

    Internet Explorer 不支持箭头函数。所以它给出了语法错误。

    参考资料:

    (1)Arrow functions support

    (2)Browser compatibility for Arrow functions

    你可以尝试使用 Babel 来解决 IE 的这个问题。

    (3)babel-plugin-transform-es2015-arrow-functions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      相关资源
      最近更新 更多