• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 React 게시판 javascript 작동안함

javascript 작동안함

9 글 보임 - 1 에서 9 까지 (총 9 중에서)
  • 글쓴이
  • #87371

    가보자고
    참가자
    이미 만들어져있는 HTML 템플릿을 React 프로젝트로 변경하였습니다
    다른거는 다 괜찮은데 javascript 파일이 적용되지 않습니다
    기존 html 템플릿에 있던 script 를 React 프로젝트 내 index.html body 태그에 옮겨 작성했습니다
    
    어떤 .js 파일은 적용되는데 어떤 파일은 적용되지 않았습니다
    렌더링 완료 시점이 차이가 나서 그런거 같은데 어떻게 해결해야할지 모르겠습니다
     
    아래는 프로젝트 구조입니다
    
     2023-06-17 22 56 01
    

    아래는 리액트 프로젝트 내 index.html 파일 입니다

     

    <div>
    <div><!DOCTYPE html></div>
    <div><html lang="en"></div>
    <div>  <head></div>
    <div>    <meta charset="utf-8" /></div>
    <div>    <meta name="viewport"</div>
    <div>        content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" /></div>
    <div>   </div>
    <div>    <title>Container - Layouts | Sneat - Bootstrap 5 HTML Admin Template - Pro</title></div>
    <div>   </div>
    <div>    <meta name="description" content="" /></div>
    <div>   </div>
    <div>    <!-- Favicon --></div>
    <div>    <link rel="icon" type="image/x-icon" href="%PUBLIC_URL%/assets/img/favicon/favicon.ico" /></div>
    <div>   </div>
    <div>    <!-- Fonts --></div>
    <div>    <link rel="preconnect" href="https://fonts.googleapis.com" /></div>
    <div>    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /></div>
    <div>    <link</div>
    <div>        href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"</div>
    <div>        rel="stylesheet" /></div>
    <div>   </div>
    <div>    <!-- Icons. Uncomment required icon fonts --></div>
    <div>    <link rel="stylesheet" href="%PUBLIC_URL%/assets/vendor/fonts/boxicons.css" /></div>
    <div>   </div>
    <div>    <!-- Core CSS --></div>
    <div>    <link rel="stylesheet" href="%PUBLIC_URL%/assets/vendor/css/core.css" class="template-customizer-core-css" /></div>
    <div>    <link rel="stylesheet" href="%PUBLIC_URL%/assets/vendor/css/theme-default.css" class="template-customizer-theme-css" /></div>
    <div>    <link rel="stylesheet" href="%PUBLIC_URL%/assets/css/demo.css" /></div>
    <div>   </div>
    <div>    <!-- Vendors CSS --></div>
    <div>    <link rel="stylesheet" href="%PUBLIC_URL%/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" /></div>
    <div>   </div>
    <div>    <!-- Page CSS --></div>
    <div>   </div>
    <div>    <!-- Helpers --></div>
    <div>    <script src="%PUBLIC_URL%/assets/vendor/js/helpers.js"></script></div>
    <div>   </div>
    <div>    <!--! Template customizer & Theme config files MUST be included after core stylesheets and helpers.js in the <head> section --></div>
    <div>    <!--? Config:  Mandatory theme config file contain global vars & default theme options, Set your preferred theme option in this file.  --></div>
    <div>    <script src="%PUBLIC_URL%/assets/js/config.js"></script></div>
    <div>  </head></div>
    <div>  <body></div>
    <div>    <noscript>You need to enable JavaScript to run this app.</noscript></div>
    <div>    <div id="root"></div></div>
    <div>    <!--</div>
    <div>      This HTML file is a template.</div>
    <div>      If you open it directly in the browser, you will see an empty page.</div>
    <div>      You can add webfonts, meta tags, or analytics to this file.</div>
    <div>      The build step will place the bundled scripts into the <body> tag.</div>
    <div>      To begin the development, run `npm start` or `yarn start`.</div>
    <div>      To create a production bundle, use `npm run build` or `yarn build`.</div>
    <div>    --></div>
    <div>        <!-- Core JS --></div>
    <div>        <!-- build:js assets/vendor/js/core.js --></div>
    <div>        <script src="%PUBLIC_URL%/assets/vendor/libs/jquery/jquery.js"></script></div>
    <div>        <script src="%PUBLIC_URL%/assets/vendor/libs/popper/popper.js"></script></div>
    <div>        <script src="%PUBLIC_URL%/assets/vendor/js/bootstrap.js"></script></div>
    <div>        <script src="%PUBLIC_URL%/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script></div>
    <div>       </div>
    <div>        <script async defer src="%PUBLIC_URL%/assets/vendor/js/menu.js"></script></div>
    <div>        <!-- endbuild --></div>
    <div>       </div>
    <div>        <!-- Vendors JS --></div>
    <div>       </div>
    <div>        <!-- Main JS --></div>
    <div>        <script src="%PUBLIC_URL%/assets/js/main.js"></script></div>
    <div>       </div>
    <div>        <!-- Page JS --></div>
    <div>       </div>
    <div>        <!-- Place this tag in your head or just before your close body tag. --></div>
    <div>        <script async defer src="https://buttons.github.io/buttons.js"></script></div>
    <div>  </body></div>
    <div></html></div>
    </div>

    
    
    		
    	
    #87401

    codingapple
    키 마스터
    script 태그들을 head태그 안에 넣어봅시다
    #87416

    가보자고
    참가자
    모든 script 태그를 index.html 파일 내 head 태그안에 뒀는데 이전에 말했던거처럼 어떤거는 작동하고 어떤거는 작동안합니다
    참고로 console에 찍히는것도 없습니다
    
    #87421

    가보자고
    참가자
    혹시몰라 깃허브에 React 코드 업로드 했습니다
    참고부탁드립니다
    https://github.com/weatherbetter/React-temp
    HTML 템플릿은 아래 파일 사용했습니다
    https://themewagon.com/themes/free-responsive-bootstrap-5-html5-admin-template-sneat/
    
    아래 이미지 캡처처럼 프로필 부분은 클릭하면 작동하는데
    옆에 사이드바가 작동하지 않습니다
    2023-06-18 11 56 04
    
    #87459

    codingapple
    키 마스터
    script 태그중에 async defer 써있는건 다 지워봅시다
    #87462

    가보자고
    참가자
    지웠는데도 안됩니다...
    #87464

    가보자고
    참가자
    Helmet 을 설치해 사용하는 자바스크립트 파일을 직접 넣어주면 작동은 합니다 
    (공유드린 깃허브 내 src/pages/Home.js 파일 참고 부탁드립니다!)
    하지만 이렇게 되면 모든 파일에 같은 방식으로 적용해야합니다 
    index.html 에 적용하고 싶습니다 어떻게 하면 좋을까요...
    
    #87507

    codingapple
    키 마스터
    자바스크립트 파일안의 내용들을 페이지 로드 완료시 실행하라고 코드를 추가하거나 
    아니면 useEffect에 복사붙여넣기 해서 써야할듯요
    #87666

    가보자고
    참가자
    감사합니다 해결했습니다!
9 글 보임 - 1 에서 9 까지 (총 9 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠