반응형
창을 삭제하는 방법.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.siteDirection
null 입니다.
어떻게 하면 해결할 수 있을까요?
언급URL : https://stackoverflow.com/questions/65824693/how-to-remove-window-nuxt-without-any-issue-from-vuex-in-nuxt
반응형
'programing' 카테고리의 다른 글
왜 모든 서브쿼리는 키워드별로 주문하기 전에 select-statement로 실행됩니다.이러한 서브쿼리는 필요하지 않은 경우에도 실행됩니다. (0) | 2022.11.21 |
---|---|
레일: 데이터베이스의 빈 문자열을 NULL로 강제 적용합니다. (0) | 2022.11.21 |
MySQL : ERROR 1215 (HY000) :외부 키 제약 조건을 추가할 수 없습니다. (0) | 2022.11.21 |
Vuejs 및 Vuex 어레이에 무선 입력 값만 입력하는 방법 (0) | 2022.11.21 |
파라미터가 다른 여러 메서드콜을 확인하는 방법 (0) | 2022.11.21 |