gpt4 book ai didi

javascript - net::ERR_ABORTED 404(未找到)Javascript

转载 作者:行者123 更新时间:2023-12-04 16:26:28 24 4
gpt4 key购买 nike

我是 javascript 新手,但由于某种原因我有这个错误
获取 http://127.0.0.1:5500/src/paddle净::ERR_ABORTED 404(未找到)
我的代码看起来像这样
index.html

<html>
<head>
<title >Game</title>
<meta charset="UTF-8" />
<style>
#gameScreen {
border: 1px solid black;

}
</style>
</head>
<body>
<canvas id="gameScreen" width="800" height="600"></canvas>
<script type="module" src="src/index.js"></script>
</body>
</html>
index.js
import Paddle from "/src/paddle";


let canvas = document.getElementById("gameScreen");

let ctx = canvas.getContext('2d');

const GAME_WIDTH = 800;
const GAME_HEIGHT = 800;


let paddle = new Paddle(GAME_WIDTH, GAME_HEIGHT);

paddle.draw(ctx);
paddle.js
export default class Paddle {
constructor(gameWidth, gameHeight) {
this.width = 150;
this.height = 30;

this.position = {
x: gameWidth / 2 - this.width / 2,
y: gameHeight - this.height - 10
};
}
draw(ctx) {
ctx.fillRect(this.position.x, this.position.y, this.width, this.height);

}

}
我在 index.js 的第一行收到错误我感谢任何帮助

最佳答案

这就是我解决这个问题的方法,而不是

import Paddle from "/src/paddle";
只需键入“js”作为灭绝
import Paddle from "/src/paddle.js";

关于javascript - net::ERR_ABORTED 404(未找到)Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62898579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com