0

Имеется страница с игрой и чтобы в нее поиграть нужно подключить game.js файл с логикой игры. Game.jsx

import React from "react";
const Game = () => {
return(
    <div>
        <h1 id="level-title">Press A Key to Start</h1>
        <div className="container">
            <div>
                <div type="button" id="green" className="btn green">
                </div>
                <div type="button" id="red" className="btn red">
                </div>
            </div>
            <div>
                <div type="button" id="yellow" className="btn yellow">
                </div>
                <div type="button" id="blue" className="btn blue">
                </div>
            </div>
        </div>
    </div>
)

}
export default Game

App.js

import React from "react";
import {BrowserRouter, Route, Routes, Link} from "react-router-dom";
import './style.css'
import './game.js'
import Game from "./pages/Game";
export default function App() {
return(
    <BrowserRouter>
         <Routes>
        <Route path="/scoreboard" element={<Scoreboard/>}>

        </Route>
        <Route path="/" element={<Game/>}>

        </Route>
        </Routes>
    </BrowserRouter>


)

}

index.html

  <body>

<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

</body>
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256- 
 H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
</html>

Подключая файл через App.js появляется ошибка: Uncaught (in promise) DOMException: Failed to load because no supported source was found.

1 ответ 1

0
import * as game from './game.js'

тогда ты сможешь использовать функции из этого файла способом ниже:

game.someFunc()

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.