简体   繁体   English

将 Skulpt 与 React 一起使用

[英]Using Skulpt with React

I'm interested in creating a React web app that teaches kids how to use Python through programs such as Turtle graphics.我有兴趣创建一个 React web 应用程序,它可以通过 Turtle 图形等程序教孩子们如何使用 Python。 I thought that Skulpt would be a good library to use since it already has a demo that shows here how to use it within a HTML page.我认为Skulpt将是一个很好的库,因为它已经有一个演示,在这里展示了如何在 HTML 页面中使用它。 However, while it loads fine in a normal web page, I'm having difficulty getting it to run in my React app, probably due to the global variables that skulpt.min.js sets.然而,虽然它在正常的 web 页面中加载良好,但我很难让它在我的 React 应用程序中运行,可能是由于 skulpt.min.js 设置的全局变量。 Specifically, I get the following message:具体来说,我收到以下消息:

./src/utils/skulpt-stdlib.js
Line 1:1:  'Sk' is not defined  no-undef

I imagine it's because the skulpt-stdlib.js script relies on the skulpt.min.js script to be read first and set its global variables before the skulpt-stdlib.js script works.我想这是因为 skulpt-stdlib.js 脚本依赖于首先读取 skulpt.min.js 脚本并在 skulpt-stdlib.js 脚本工作之前设置其全局变量。 What would I need to do in React to get this to work the same way it does in a normal web page?我需要在 React 中做什么才能让它像在普通 web 页面中一样工作? Thank you!谢谢!

try this, hope this works, i am also trying, i will update this if it works completely.试试这个,希望它有效,我也在尝试,如果它完全有效,我会更新它。

add the below code in the beginning of skulpt.min.js在 skulpt.min.js 的开头添加以下代码

function Sk() {}

and the below code in the end of skulpt.min.js以及 skulpt.min.js 末尾的以下代码

export { Sk };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM