programing

창을 삭제하는 방법.Nuxt의 Vuex에서 문제없이 __NUXT__

randomtip 2022. 11. 21. 22:30
반응형

창을 삭제하는 방법.Nuxt의 Vuex에서 문제없이 __NUXT__

Nuxt 2.13을 사용하고 있는데, 이 때문에window.__Nuxt__(function(a,b,c,d,.....))그게 제 SEO에 영향을 미칠지 모르겠지만 신경에 거슬리고 제 언어파일이 다 나와요.

여기 상황이 있습니다.이 상황에는lang.json내 앱에 파일을 저장한다. 나는 그것을 읽고lang에 명시하다.Vuex.그렇지만window.__Nuxt__내가 원하지 않는 언어를 보여줍니다!!

지금까지 이 문제를 제거하기 위한 세 가지 해결책을 찾았습니다.

1: 이 코드를 nuxt.config.dlink to stack answer에 추가합니다.

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

2: 일부 코드를 코멘트하여node_module/@nuxt/vue-renderer/dist/vue-renderer.js 기사에 링크하다

3: 치어리더 패키지를 사용하여 본문 링크에서 기사까지의 스크립트를 스크랩합니다.

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 script in the body,
      //So I removed the first script tag in the body
      this.$(`body script`).eq(0).remove();
      result.html = this.$.html()
    }
  }
}

세 가지 모두 작업을 할 수 있지만, Vuex의 상태를 사용하여 느린 부하에 대한 테마 주소를 제공하기 때문에 컴포넌트는 더 이상 게으르지 않습니다.예를 들어 다음과 같습니다.

computed:{
  mycomponent(){
    return ()=>import(`~/components/${this.$store.state.siteDirection}/mycomp.vue`)
  }
}

웹 팩이 이것을 로딩할 수 없다는 오류를 발생시킵니다.this.$store.state.siteDirectionnull 입니다.

어떻게 하면 해결할 수 있을까요?

언급URL : https://stackoverflow.com/questions/65824693/how-to-remove-window-nuxt-without-any-issue-from-vuex-in-nuxt

반응형