ssr,nuxt2··约 6 分钟读完·642 次观看

nuxt2发布出现的问题

上传到服务器就是这样,static这个文件必须放在src下面。第三步:在上传文件到服器的时候,需要上传以下几个文件。第二步:这个时候进行打包发布,会找不到。
vue.js

在nuxt2进行打包的时候,遇到图标不出现

解决办法

第一种解决方法

  • 第一步:在nuxt2中nuxt.conifg.jd中使用srcDir: 'src/',把所有文件放在src下面, nuxt.config.js
js
      
        
          1
          
          import path from 'path'
        
          2
          
          export default {
        
          3
          
            // Global page headers: https://go.nuxtjs.dev/config-head
        
          4
          
            head: {
        
          5
          
              title: 'e',
        
          6
          
              htmlAttrs: {
        
          7
          
                lang: 'en'
        
          8
          
              },
        
          9
          
              meta: [
        
          10
          
                { charset: 'utf-8' },
        
          11
          
                { name: 'viewport', content: 'width=device-width, initial-scale=1' },
        
          12
          
                { hid: 'description', name: 'description', content: '' },
        
          13
          
                { name: 'format-detection', content: 'telephone=no' }
        
          14
          
              ],
        
          15
          
              link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
        
          16
          
            },
        
          17
          
          
        
          18
          
            // Global CSS: https://go.nuxtjs.dev/config-css
        
      
    

目录结构

  • 第二步:这个时候进行打包发布,会找不到link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  • 第三步:在上传文件到服器的时候,需要上传以下几个文件

上传到服务器就是这样,static这个文件必须放在src下面

  • 第四步:接下来就可以直接yarn,然后yarn start,就可以访问到了(前提是已经配置好了nginx进行转发,进行转发的时候,不要忘记配置服务器端口)

第二种解决方法

  • 可以直接使用link: [{ rel: 'icon', type: 'image/x-icon', href: '线上地址' }

这篇文章对你有帮助吗?