运行npm run start(&M);npm run dev在我的代码中产生了不同的结果.我打算在生产环境中运行代码,使其像在开发环境中一样工作,但是当我分别运行它们时,并没有按照预期进行渲染.

Code Reference:

下拉部分

  <v-list-group>
    <template v-slot:activator>
      <v-list-item-content>
        <v-list-item-title>About Us</v-list-item-title>
      </v-list-item-content>
    </template>

    <v-list-item
      v-for="(item, index) in navItems[2].content"
      :key="index"
      :to="item.link"
    >
      <v-list-item-title v-text="item.name"></v-list-item-title>
    </v-list-item>
  </v-list-group>

    
navItems: [
{name: '', link: '', content: [{name: '', link: ''}]},{}{
{name: '', link: '', content: [{name: '', link: ''}]},
name: "aboutus",
      link: "",
      content: [
            { name: "Vision", link: "/about/vision" },
            { name: "Partner With Us", link: "/about/partnership" },
          ],
}]

图像卡部分

<v-card
  nuxt
  id="btn-home-forest"
  to="/industry/forestry"
  class="mx-0 bgMidPurple borderSharpTopBtmRound pb-3"
  max-width="276"
>
  <v-img
    :src="require('~/assets/images/forestry_button.png')"
    height="208px"
  ></v-img>

  <v-card-title
    class="textWhite textBody"
  >
    Forestry
  </v-card-title>

</v-card>

Nuxt Config JS

import colors from 'vuetify/es5/util/colors'

export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  generate: {
    exclude: ['/blog', '/pricing'],
    fallback: '404.html'
  },
  target: 'static',
  server: {
    host: '0.0.0.0',
    port: 8888
  },
  head: {
    titleTemplate: '%s',
    title: 'nuxt-vuetify-basic',
    htmlAttrs: {
      lang: 'en',
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' },
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/EoF-Logo.png' }
    ],
  },
  env:{
  },
  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    '@assets/global.css'
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [ 
    '@plugins/vue-recaptcha-v3.js',
    '@/plugins/vuelidate',
    '@/plugins/vue-country-code'
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    '@nuxtjs/vuetify',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    '@nuxtjs/axios', 'cookie-universal-nuxt'
  ],

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    baseURL: '/',
  },
  router:{
    //middleware: ['']
  },

  // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
  vuetify: {
    treeShake: false,
    theme: {
      dark: true,
      themes: {
        dark: {
          primary: colors.blue.darken2,
          accent: colors.grey.darken3,
          secondary: colors.amber.darken3,
          info: colors.teal.lighten1,
          warning: colors.amber.base,
          error: colors.deepOrange.accent4,
          success: colors.green.accent3,
        },
      },
    },
  },
  build: {
    publicPath: '/public',
    filenames: {
      chunk: 'js/[id].[contenthash].js'
    },
    extractCSS: true,
    optimization: {
      splitChunks: {
        cacheGroups: {
          styles: {
            name: 'styles',
            test: /\.(css|vue)$/,
            chunks: 'all',
            enforce: true
          }
        }
      }
    },
    transpile: [
      'vuetify/lib',
    ],
  },
}

Production Config

Production Environment

Production Dropdown

Production Dropdown

Production Image Card

Production Image Card

Production Console Error Code Error Code in Prod

Development Config

Development Environment

Development Dropdown

Dev Dropdown

Development Image Card

Dev Image Card

Development Console Error Code Error Code in Dev

为什么与dev相比,生产环境中的组件都在运行相同的代码,却出现了中断?

我已经参考了下面的链接来解决我所面临的问题,这可能是最接近我所面临的问题,但它也不起作用.

Nuxt production mode loading resources late?

Why is my Vue JS Nuxt lazy loaded component bundled in app.js, not loaded separately?

推荐答案

OP解决了这个问题,他将自己的内容包装在client-only标记中,以防止DOM不匹配.更多详情请参见我的previous answer.

此外,请记住,这不会在服务器上渲染嵌套零件(在构建期间).

Vue.js相关问答推荐

v-model 修饰符返回空

Vue index.html favicon 问题

v-for 内部的组件

如何将对象作为props传递并让组件更新子对象

如何将 axios/axios 拦截器全局附加到 Nuxt?

如何修复跨域读取阻塞 (CORB) 阻止了 MIME 类型应用程序/json 的跨域响应问题?

将自定义部分添加到 v-autocomplete 下拉列表

如何从 .vue 文件中导出多个对象

将 Vuetify 从 1.5 升级到 2 时,Sass-loader 错误 'options has an unknown property 'indentedSyntax''

Vue 组件 Vue-Instant

Vue路由安全

我可以修改 Vue.js VNodes 吗?

在手动安装的 vue 组件中使用 vuex

如何将项目推送到 Vuejs 中数据对象的数组中? Vue 似乎没有关注 .push() 方法

重新加载页面正在 vue 组件中的插槽上闪烁内容

过渡后的 v-if 下方的过渡元素

Vue.js 3 - 替换/更新react性对象而不会失go react性

在Vue中调用方法时的括号

Vuejs 组件等待 facebook sdk 加载

禁用外部主题文件产生的 Dart SASS 警告