visual-studio-code - 在 Visual Studio Code 中使用 p5.js 访问文件
问题描述
我是一个新手,刚开始使用 p5.js,刚刚开始使用 Visual Studio Code,并且在使用任何访问文件的函数时遇到问题,无论是图像还是文本。我的目标是加载一个文本文件,以便将其解析为词汇数据。
在参考文档之后,我添加了预加载。您可以看到我也尝试使用图像文件执行此操作,并且产生了相同的结果。
function preload(){
fileContents = loadStrings('defaultvocab.txt');
//img = loadImage('AthensDemocracy.jpg');
}
结果是这组错误消息 和预加载中的挂起。
我不确定它是 VSCode 的设置还是我需要在它创建的 JSON 文件中做的事情,我必须添加文件才能让它也能工作,所以它可能是要添加的东西,但我我没有太多运气找到它。目前launch.json是这样的:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}",
"file":"index.html"
}
]
请原谅悲伤的 90 年代网页设计,感谢您的帮助!
解决方案
看起来网页仍在通过本机文件系统路径而不是本地 Web 服务器 (localhost:8080) 加载。
如果您在浏览器中手动打开htts://localhost:8080是否会运行(Web 服务器是否实际运行?)
就个人而言,我使用 Sam Levigne 的p5.vscode 插件:
- 安装它
- 右键单击您的 index.html
- 单击使用 Live Server 打开
我发现实时编码(保存时自动重新加载)非常有用,尤其是在原型设计时。
推荐阅读
- c# - 我还能为 sql 命令使用参数吗?
- python - Python 装饰器中的语法错误
- youtube-api - 格式化 api url 以仅返回 videoId。(并使用最小配额)
- java - java中的org/codehaus/groovy/control/CompilationFailedException
- sql-server - SQL Server 还原分离数据库
- django - ModuleNotFoundError:没有名为“drf_multiple_model”的模块
- javascript - 电子邮件地址正则表达式验证
- python - 如何检查列表的子子列表是否包含一项,如果是,则将其删除?
- jenkins - 有没有办法查看詹金斯插件更新历史?
- javascript - 在 JSX 文件中导入 css