我在 Nuxt v2.13 和 Vuetify v2 上,也在我的默认布局中使用 keep-alive 。随着我的应用程序变得越来越大,我越来越注意到内存问题,因此我的应用程序在云服务器上至少需要大约 4GB 的 RAM 才能构建和正常运行。我四处挖掘,发现零散的碎片,所以决定分享它们并讨论解决方案。
请根据他们的#numbers回答每一个
#1 - NuxtLink (vue-router) 内存泄漏: 其他人发现 vue-router 可能存在泄漏;还因为与 nuxt-link 关联的 DOM 将被预取,因此内存使用率也可能很高。所以有人建议使用 html 锚而不是像这样的 nuxt-link:
<template>
<a href="/mypage" @click.prevent="goTo('mypage')">my page link</a>
</template>
<script>
export default{
methods:{
goTo(link){
this.$router.push(link)
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
你怎么看这种方法?那么 Vuetify toprops怎么样,因为它们像 nuxt-link 一样工作?
<template>
<v-card to="/mypage" ></v-card>
</template>
Run Code Online (Sandbox Code Playgroud)
#2 - 动态组件加载:
由于我的应用程序是双向的并且可以通过.env文件自定义,我不得不像这样动态地和有条件地延迟加载我的许多组件:
<template>
<component :is="mycomp" />
</template>
<script>
export default{
computed:{
mycomp(){
return import()=>(`@/components/${process.env.SITE_DIR}/mycomp.vue`)
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
这会导致高内存使用率/泄漏吗?? …
我在 Nuxt 2.13 上遇到了window.__Nuxt__(function(a,b,c,d,.....)). 我不知道它是否会影响我的 SEO,但它让我很紧张,并显示了我所有的语言文件。
这是情况:lang.json我的应用程序中有一个文件。我阅读了它并将其存储lang在Vuex. 但window.__Nuxt__显示了我不想要的语言!!
到目前为止,我已经找到了三个解决方案来删除它:
1:通过将此代码添加到 nuxt.config.js 链接到堆栈答案
hooks: {
'vue-renderer:ssr:context'(context) {
const routePath = JSON.stringify(context.nuxt.routePath);
context.nuxt = {serverRendered: true, routePath};
}
}
}
Run Code Online (Sandbox Code Playgroud)
2:通过评论文章链接中的一些代码node_module/@nuxt/vue-renderer/dist/vue-renderer.js
const cherrio = const cheerio = require('cheerio');
export default {
//The rest configuration is omitted
hooks: {
'render:route': (url, result) => {
this.$ = cheerio.load(result.html,{decodeEntities: false});
//Since window.__nuxt__ is always located in the first …Run Code Online (Sandbox Code Playgroud) 我正在使用 Nuxt 2.15.4 和 nuxt/vuetify 1.11.3
我的项目工作正常,但是当我在构建时将其移至新服务器时,出现以下错误:
这是我的 package.json 文件
{
"name": "myproject",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"@nuxtjs/auth": "^4.9.1",
"@nuxtjs/axios": "^5.13.1",
"@nuxtjs/device": "^2.1.0",
"@nuxtjs/google-gtag": "^1.0.4",
"@nuxtjs/gtm": "^2.4.0",
"chart.js": "^2.9.3",
"cookie-universal-nuxt": "^2.1.4",
"core-js": "^3.9.1",
"jquery": "^3.5.1",
"nuxt": "^2.15.3",
"swiper": "^5.4.5",
"v-viewer": "^1.5.1",
"vee-validate": "^3.3.7",
"vue-awesome-swiper": "^4.1.1",
"vue-chartjs": "^3.5.0",
"vue-cropperjs": "^4.1.0",
"vue-easy-dnd": "^1.10.2",
"vue-glide-js": "^1.3.14",
"vue-persian-datetime-picker": "^2.2.0",
"vue-product-zoomer": "^3.0.1",
"vue-slick-carousel": "^1.0.6",
"vue-sweetalert2": "^4.2.1",
"vue2-editor": "^2.10.2",
"vuedraggable": …Run Code Online (Sandbox Code Playgroud) 我使用的是 Nuxtjs 2.15.7,最近在我的控制台中收到此错误
当我搜索时,只需要@nuxt/pwa 发布. 但我的项目中没有pwa模块!
这是我的 package.json
{
"name": "my-app",
"version": "2.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"dev:host": "nuxt --hostname 0.0.0.0 --port 8000",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"@nuxtjs/auth": "^4.9.1",
"@nuxtjs/axios": "^5.13.1",
"@nuxtjs/device": "^2.1.0",
"@nuxtjs/google-gtag": "^1.0.4",
"@nuxtjs/gtm": "^2.4.0",
"cookie-universal-nuxt": "^2.1.4",
"core-js": "^3.15.1",
"nuxt": "^2.15.7",
"swiper": "^5.4.5",
"v-viewer": "^1.5.1",
"vee-validate": "^3.3.7",
"vue-awesome-swiper": "^4.1.1",
"vue-cropperjs": "^4.1.0",
"vue-easy-dnd": "^1.12.2",
"vue-persian-datetime-picker": "^2.2.0",
"vue-product-zoomer": "^3.0.1",
"vue-sweetalert2": "^4.2.1",
"vue2-editor": "^2.10.2",
"vuedraggable": "^2.24.0"
},
"devDependencies": { …Run Code Online (Sandbox Code Playgroud) 我正在构建一个 Nuxt-electron-prisma 应用程序,但我有点卡在这里。当我按照指导正常使用 prisma 时,开发时一切正常,但在构建时出现此错误:
\nA javascript error occurred in the main process\nUncaught exception:\nError: can not find module : \'.prisma/client\'\nRun Code Online (Sandbox Code Playgroud)\n我尝试将 prisma 提供程序输出更改为../resources/prisma/client
A javascript error occurred in the main process\nUncaught exception:\nError: can not find module : \'.prisma/client\'\nRun Code Online (Sandbox Code Playgroud)\n在 Electron 的 main.js 中
\ngenerator client {\n provider = "prisma-client-js"\n output = "../resources/prisma/client"\n}\nRun Code Online (Sandbox Code Playgroud)\n但我Cannot find module \'_http_common\' at webpackMissingModules在开发和构建中都遇到错误!其他人认为这是在客户端使用 prisma 时引起的,但我只在background.js(main.js我的样板)上使用它
我正在为 Nuxt- Electron 使用Nuxtron样板,它使用 …
我使用的是 Nuxtjs 2.13,我想知道“我应该如何删除事件侦听器(有必要吗??)”。
我不是在谈论 jsaddEventListener和removeEventListener. 我更好奇的是this.$emit(),$nuxt.$emit()和$nuxt.$on()。有没有办法删除$nuxt.$on()或侦听组件,<mycomp @myevent="do()" />是否beforeDestroy()有必要?
由于我的 Nuxt 项目在我的服务器上使用了如此多的 RAM,我认为需要进行一些优化。
我正在使用vue-awesome-swiper但最近我在移动设备上遇到了一些问题(我有一个按钮轮播,当我单击其中一个按钮时,单击 btn 需要大约一两秒的时间)并且作为该包自2020年以来一直没有更新并且仍在使用swiper v5,我决定使用Swiper js本身。我已经按照文档中的说明进行操作,但出现dependency not found错误
包.json
{
"name": "myapp",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"dev:host": "nuxt --hostname 0.0.0.0 --port 8000",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"@nuxtjs/axios": "^5.13.6",
"@nuxtjs/device": "^2.1.0",
"core-js": "^3.15.1",
"nuxt": "^2.15.7",
"swiper": "^7.0.9",
"vuetify": "^2.5.5"
},
"devDependencies": {
"@nuxtjs/vuetify": "^1.12.1",
"@mdi/font": "^5.9.55",
"@nuxtjs/dotenv": "^1.4.1",
"noty": "^3.2.0-beta",
"nuxt-gsap-module": "^1.2.1",
"sass": "1.32.13"
}
}
Run Code Online (Sandbox Code Playgroud)
测试.vue
<template>
<div class="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide" …Run Code Online (Sandbox Code Playgroud) nuxt.js ×7
vue.js ×4
vuejs2 ×3
javascript ×2
vuetify.js ×2
electron ×1
memory-leaks ×1
node.js ×1
prisma ×1
sass-loader ×1
swiper.js ×1
vee-validate ×1
vuex ×1
web-worker ×1
workbox ×1