简体   繁体   English

如何在nuxt项目中删除window._nuxt_,它对我来说太大了

[英]How to remove window._nuxt_ in nuxt project, it is too large for me

When I use nuxt to develop my project, I find some problems.我在使用nuxt开发项目的时候,发现了一些问题。

window.__NUXT__=(function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,_,$,aa, ..... code was too larger

can I remove it or use js file to replace it?我可以删除它或使用 js 文件来替换它吗?

I have found a relatively perfect solution.我找到了一个相对完美的解决方案。 I will share it with you here.我将在这里与您分享。 You can also take a look at the website I developed using NUXT Sample Website你也可以看看我用NUXT Sample Website开发的网站

The key is the hook function vue-renderer:ssr:context , you can set the context.nuxt = null to remove any data in window._NUXT_ .关键是hook函数vue-renderer:ssr:context ,你可以设置context.nuxt = null来移除window._NUXT_中的任何数据。

But it is not work well, you have to add serverRender and routePath to window.nuxt但效果不佳,必须在window.nuxt添加serverRenderroutePath

// nuxt.config.js
{
...,
hooks: {
    'vue-renderer:ssr:context'(context) {
      const routePath = JSON.stringify(context.nuxt.routePath);
      context.nuxt = {serverRendered: true, routePath};
    }
  }
}

You can see the result at my site你可以在我的网站上看到结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM