Vuetify/NUXT生产环境组件在开发环境中无法正常工作
运行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
开发下拉
开发图像卡
,当它们都在运行相同的代码时,组件与开发环境相比,组件在生产环境中的破裂是相比的?
我已经提到以下以下链接来解决我面临的问题,该问题可能是与我所面临的最接近的问题,但它也不起作用。
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 Dropdown
Production Image Card
Development Config
Development Dropdown
Development Image Card
Development Console Error Code
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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).
感谢Kissu指出了修复DOM不匹配的重要性。
遵循提供的文章/答案
原始代码和错误
已修复到导致错误的代码
遵循以下链接以进行故障排除&amp;引脚指向产生误差的确切DOM元素。
Thanks to Kissu for pointing out the significance of fixing the DOM mismatch.
Followed the article/answer provided
Original Code with Error
Fixed to code causing error
Followed the following link to troubleshoot & pin point to the exact DOM element producing the error.