问题标签 [codesandbox]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
reactjs - Codesandbox 为 React 应用程序提供“目标容器不是 DOM 元素”错误,但 webpack-dev-server 没有
我正在尝试将我的 git repo 与一个练习 React 应用程序一起放入 codeandbox.io,以便我可以更轻松地向其他人展示它。我按照这里的说明进行操作:https ://codesandbox.io/s/github/cdpautsch/react-learning-area/tree/master/test-app2
但是,我收到错误:Target container is not a DOM element
当我使用 webpack-dev-server 运行时,此错误不会出现在我的机器上。
我的代码来自index.js
:
我的代码来自index.html
:
它说它不是一个有效的元素,但它肯定存在并且肯定有正确的名称。我错过了什么?
使用附加信息进行更新: * 应用程序不是用 . 创建的create-react-app
,而是手动初始化和加载包 * 沙盒似乎默认为 CRA,这可能会影响它的运行方式?
window.location - 如何在codeandbox.io 中使用window.location.href?
我想window.location.href
在工具codeandbox.io中使用。这是因为我想在发生硬页面加载的情况下进行测试。但是,我遇到了一个问题。
我收到此错误:
示例: https ://codesandbox.io/s/locationhref-usage-nyvfi (查看src/index.ts
并打开开发控制台)
如何在假的虚拟浏览器中实现模拟页面加载的能力?
javascript - 如何在 React 组件的状态下拼接数组
我正在制作一个时间表应用程序。index.js 呈现表格。表格的行从子数组中读取。children 数组读取状态以保持自身更新。AddRow() 工作正常。DeleteRow() 有一些问题。我打算从事件中获取 parentNode id,查找状态的数组,拼接它并让孩子自己更新——这反过来又更新了渲染。因此,当一行被删除时,它会从状态数组中拼接出来,然后在 children 数组中更新,然后再渲染。DeleteRow 运行除 array.splice 或 indexOf 部分之外的所有内容。我什至尝试了一个 for 循环,但它不起作用。我的方法正确吗?
javascript - 按钮点击结果:HTML中的“'功能'未定义”
我正在使用 CodeSandbox 为我的社交媒体编写本地化访问点(只是为了玩他们拥有的 Vanilla 包裹包)。现在,我的按钮调用了单独的函数,但是当我选择一个按钮时,错误“Function
未定义”
我的按钮函数存储在与常规 JavaScript 不同的文件中。
我查看了 W3Schools 以了解这是如何完成的。有几次我什至尝试将函数放在 HTML 页面本身中,看看是否有帮助;但是,错误仍然出现。
下面是一个 HTML 示例:
这是js函数:
当我按下按钮显示不和谐小部件时,我期望输出。相反,我产生了上述错误。我最好的猜测是我缺少一段代码来调用该函数。在控制台中,我收到此错误:
sShowFunction' is defined but never used. (no-unused-vars)
reactjs - 使用 Codesandbox 上的 React 获取:跨域错误
我在 Codesandbox 上的 React 应用程序中有以下 fetch 调用: https ://codesandbox.io/s/react-fetch-example-for-so-vxxie
如果我激活任何一条线
.then(console.log(data))
或者
loadOptions={this.state.data}
我得到: 引发了跨域错误。React 无法访问开发中的实际错误对象。有关更多信息,请参阅 https://fb.me/react-crossorigin-error。
为什么以及如何解决这个问题?
(请注意我在 fb.me 前面添加了一个空格,以便在 StackOverflow 上通过验证)
stackblitz - 为什么我收到此错误 (new Set(...)).slice is not a function?
我尝试在任何在线代码编辑器中运行此代码,但总是出错
(new Set(...)).slice 不是函数
代码:
为什么我得到这个错误?
javascript - 如何在 Codesandbox 中使用 Babel Plugin Proposal Throw Expressions?
在 Codesandbox 中使用 React 我试图抛出新的错误('出错了');我有这个错误:
我已经添加了这个依赖:https ://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions仍然无法工作。
这是我的代码
javascript - 我的代码框上带有 react & parcel 的“目标容器不是 DOM 元素”错误
我的项目在我的电脑上运行,但现在CodeSanbox
我遇到了错误
目标容器不是 DOM 元素
该项目只是一个使用react
&的模板项目parcel
。我的家庭项目和codesanbox上的项目之间没有任何改变。
javascript - Why does codesandbox.io log the eventual state of my array?
I was sure this expression
Should return [1,2,3]
. Actually, if write it in the browser console it'll return what expected. But I accidentally open codesandbox and write the same code there and I got as the answer is [1,2,3,4]
. And I'm really confused in my knowledge :) I don't know why it's happening. I think it's because of bundler, I tried Parcel and WebPack bundlers both have the same result. But as I said I'm not sure. If anyone knows I would love to read it.