如何删除 nuxt 项目中的 window._nuxt_,它对我来说太大了
How to remove window._nuxt_ in nuxt project, it is too large for me
当我使用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
我可以删除它还是使用js文件替换它?
我找到了一个比较完美的解决方案。我将在这里与您分享。也可以看看我用NUXT开发的网站Sample Website
关键是hook
函数vue-renderer:ssr:context
,可以设置context.nuxt = null
删除window._NUXT_
中的任何数据。
但效果不佳,你必须将serverRender
和routePath
添加到window.nuxt
// nuxt.config.js
{
...,
hooks: {
'vue-renderer:ssr:context'(context) {
const routePath = JSON.stringify(context.nuxt.routePath);
context.nuxt = {serverRendered: true, routePath};
}
}
}
你可以在my site
看到结果
当我使用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
我可以删除它还是使用js文件替换它?
我找到了一个比较完美的解决方案。我将在这里与您分享。也可以看看我用NUXT开发的网站Sample Website
关键是hook
函数vue-renderer:ssr:context
,可以设置context.nuxt = null
删除window._NUXT_
中的任何数据。
但效果不佳,你必须将serverRender
和routePath
添加到window.nuxt
// nuxt.config.js
{
...,
hooks: {
'vue-renderer:ssr:context'(context) {
const routePath = JSON.stringify(context.nuxt.routePath);
context.nuxt = {serverRendered: true, routePath};
}
}
}
你可以在my site
看到结果