Vuetify/NUXT生产环境组件在开发环境中无法正常工作

发布于 2025-02-10 14:13:02 字数 5972 浏览 0 评论 0原文

运行npm运行start& NPM Run Dev在我的代码中产生不同的结果。我打算在生产中运行代码,以使其像开发中一样工作,但是当我分别运行它们时,并没有按预期进行渲染。 我已将代码和屏幕截图附加到代码并渲染视图。

代码参考:

下拉部分

  <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',
    ],
  },
}

生产配置

​a href =“ https://i.sstatic.net/yiw3f.png” rel =“ nofollow noreferrer”>

生产图像卡

“生产图像卡”

生产控制台错误代码 中,

开发config

“开发环境”

开发下拉

“

开发图像卡

开发控制台错误代码

,当它们都在运行相同的代码时,组件与开发环境相比,组件在生产环境中的破裂是相比的?

我已经提到以下以下链接来解决我面临的问题,该问题可能是与我所面临的最接近的问题,但它也不起作用。

nuxt生产模式加载资源迟到吗?

<为什么我是我的vue js nuxt懒惰加载的组件捆绑在app.js中,未单独加载?

Running npm run start & npm run dev is producing different outcomes in my code. I intend to run the code in production to make it work as it does in development, however when I ran them respectively, is not rendering as intended.
I have attached codes and screenshot to the code and rendered view.

Code Reference:

Dropdown Section

  <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" },
          ],
}]

Image Card Section

<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

Why are the component breaking in production environment as compared to dev, when they are both running the same code?

I have referred to the following links below to troubleshoot the issue I'm facing in which could possibly be the closest to what I'm facing but it doesn't work either.

Nuxt production mode loading resources late?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒与心事 2025-02-17 14:13:02

OP通过将其内容包裹在client-forly-code>标签中以防止DOM不匹配来解决问题。可以在我的

另外,请记住,这不会在服务器上(在构建时间)呈现嵌套的零件。

OP solved the issue by wrapping his content inside of a client-only tag to prevent the DOM mismatch. More details could be found on my previous answer.

Also, keep in mind that this will not render the nested part on the server (during build time).

执着的年纪 2025-02-17 14:13:02

感谢Kissu指出了修复DOM不匹配的重要性。
遵循提供的文章/答案

原始代码和错误

<v-slide-item
      v-for="item in tabTwoRange"
      :key="item"
       class="mx-md-3 mx-1 my-2"
    >
    <v-btn v-text="`• ${item}`" @click="TabTwo = item" :color="TabTwo === item ? 'textPurple' : 'textBlack'" class="bgWhite elevation-0 textBtn">-{{item}}</v-btn>
  </v-slide-item>

已修复到导致错误的代码

 <client-only>
    <v-slide-item
      v-for="item in tabTwoRange"
      :key="item"
      class="mx-md-3 mx-1 my-2"
    >
      <v-btn v-text="`• ${item}`" @click="TabTwo = item" :color="TabTwo === item ? 'textPurple' : 'textBlack'" class="bgWhite elevation-0 textBtn">-{{item}}</v-btn>
    </v-slide-item>
 </client-only>

遵循以下链接以进行故障排除&amp;引脚指向产生误差的确切DOM元素。

Thanks to Kissu for pointing out the significance of fixing the DOM mismatch.
Followed the article/answer provided

Original Code with Error

<v-slide-item
      v-for="item in tabTwoRange"
      :key="item"
       class="mx-md-3 mx-1 my-2"
    >
    <v-btn v-text="`• ${item}`" @click="TabTwo = item" :color="TabTwo === item ? 'textPurple' : 'textBlack'" class="bgWhite elevation-0 textBtn">-{{item}}</v-btn>
  </v-slide-item>

Fixed to code causing error

 <client-only>
    <v-slide-item
      v-for="item in tabTwoRange"
      :key="item"
      class="mx-md-3 mx-1 my-2"
    >
      <v-btn v-text="`• ${item}`" @click="TabTwo = item" :color="TabTwo === item ? 'textPurple' : 'textBlack'" class="bgWhite elevation-0 textBtn">-{{item}}</v-btn>
    </v-slide-item>
 </client-only>

Followed the following link to troubleshoot & pin point to the exact DOM element producing the error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文