美文网首页
nuxt alert is not defined

nuxt alert is not defined

作者: 滚石_c2a6 | 来源:发表于2017-11-13 11:35 被阅读554次

    window or document undefined?

    This is due to the server-side rendering. If you need to specify that you want to import a resource only on the client-side, you need to use the process.browser variable.

    For example, in your .vue file:

    if (process.browser) {
      require('external_library')
    }
    

    If you are using this library within multiple files, we recommend that you add it into your
    vendor bundle

    nuxt.config.js:

      build: {
        vendor: ['external_library']
      }
    

    在服务端渲染,找不到浏览器的window对象,alert也属于浏览器的api,
    需要添加条件来判断是否在浏览器端
    if (typeof window !== 'undefined'){
    }

    参考:https://nuxtjs.org/faq/window-document-undefined

    相关文章

      网友评论

          本文标题:nuxt alert is not defined

          本文链接:https://www.haomeiwen.com/subject/huaamxtx.html