我只是用
const fetch = require('node-fetch')
Run Code Online (Sandbox Code Playgroud)
我得到
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js from C:\Users\Alex\Desktop\rollbot\index.js not supported.
Instead change the require of C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js in C:\Users\Alex\Desktop\rollbot\index.js to a
dynamic import() which is available in all CommonJS modules.
{
code: 'ERR_REQUIRE_ESM'
}
Run Code Online (Sandbox Code Playgroud)
我的所有其他包都可以工作,只有 node-fetch 可以做到这一点。为了使用node-fetch,我应该做什么?
这件事情很完美
<select name="selectbox" onchange="alert(this.value)">
Run Code Online (Sandbox Code Playgroud)
但我想选择文字.我试过这种方式
<select name="selectbox" onchange="alert(this.text)">
Run Code Online (Sandbox Code Playgroud)
它显示未定义.我找到了如何使用DOM来获取文本.但我想以这种方式做到这一点,我的意思就像使用this.value.
我是一名 JavaScript 初学者,我正在尝试使用一个主数组中的值创建两个不同的数组。
我的主要阵列看起来像:
0: Array(3) [ 2011, 127072.7, 51584 ]
1: Array(3) [ 2012, 125920.3, 59974 ]
2: Array(3) [ 2013, 129305.4, 15468 ]
3: Array(3) [ 2014, 135364, 84554 ]
4: Array(3) [ 2015, 136757, 98754 ]
5: Array(3) [ 2016, 155653.5, 155548 ]
6: Array(3) [ 2017, 164130.5, 284848 ]
Run Code Online (Sandbox Code Playgroud)
我需要创建两个数组,首先看起来像:
0: Array(2) [ 2011, 127072.7]
1: Array(2) [ 2012, 125920.3]
2: Array(2) [ 2013, 129305.4]
3: Array(2) [ 2014, 135364]
4: Array(2) [ 2015, 136757]
5: …Run Code Online (Sandbox Code Playgroud) 我正在阅读有关Promise的MDN手册,我发现这两种方法与我相似:
它们都接受一个可迭代对象并返回一个包含已完成的Promises的数组。
那么,它们之间有什么区别呢?
我知道打字稿类型不是运行时变量。但是有什么解决方法可以打印类型名称和变量吗?
type TestDto = {
active: number;
user_name: string;
};
Run Code Online (Sandbox Code Playgroud)
console.log(TestDto);
Run Code Online (Sandbox Code Playgroud)
扔 only refers to a type, but is being used as a value here.
我想根据 TS 类型创建对象属性。我想创建具有活动属性和user_name一些默认值的JS 对象
Elasticsearch 本身就是一个数据库吗?使用它作为我的主数据库安全吗?作为我存储敏感数据的主数据库是否安全?
我正在尝试使用 Fetch 将一些数据带入屏幕,但是某些字符显示奇怪的 \xef\xbf\xbd 符号,我认为这与转换特殊字符有关。
\n\n在服务器端调试或在浏览器上调用 servlet 时,问题不会发生,因此我认为问题出在我的 JavaScript 上。请参阅下面的代码:
\n\nvar myHeaders = new Headers();\r\nmyHeaders.append(\'Content-Type\',\'text/plain; charset=UTF-8\');\r\n\r\nfetch(\'getrastreiojadlog?cod=10082551688295\', myHeaders)\r\n .then(function (response) {\r\n return response.text();\r\n })\r\n .then(function (resp) {\r\n console.log(resp);\r\n });Run Code Online (Sandbox Code Playgroud)\r\n我认为这可能是一些细节,但我还没有设法找出发生了什么。欢迎提供任何建议\n谢谢
\n我正在使用以下代码在客户端发出 fetch 请求:
var request = new Request(`http://ip:8080/click?url=${value}`, {
method: 'GET',
headers: new Headers({
"Content-Type": "application/json"
}),
});
fetch(request)
Run Code Online (Sandbox Code Playgroud)
但是当浏览器发出请求时,它会自动将URL更改为https协议:
https://ip:8080/click?url=${值}
注:网页有SSL加密
随后,我在网页控制台上收到此错误:无法加载资源:net::ERR_CONNECTION_CLOSED
我尝试在本地主机上使用fetch,但没有成功。
这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
fetch("hi.txt").then(function(response){
response.text().then(function(text){
alert(text)
})
})
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
hi.txt 文件与脚本文件位于同一文件夹中。
控制台中显示以下错误:
index.html:12 Fetch API cannot load file:///C:/~~~~/hi.txt. URL scheme "file" is not supported.
(~~~) 是路径
我希望能够在 Astro 中拥有一个动态页面来呈现 Astro 组件。我深入研究了文档和代码,但找不到像下面这样的函数(Astro.render)。理想情况下,我可以将属性传递给它。我正在寻找类似的东西react.renderToString。
import Example from './components/Example.astro'
export async function get() {
return {
body: Astro.render(Example)
};
}
Run Code Online (Sandbox Code Playgroud)
更新:我认为这里的每个答案都是错误的。给定一个 astro 文件,我想要一个node独立于运行时 astro 框架的函数,它可以接受 astro 文件并简单地返回一个Response(因为我知道 astro 文件可以返回来自 front-matter 的响应)和/或HTML字符串?我认为它可以是像这样的元组[res, htmlString]。就像可以转换 Markdown 文件一样,astro 文件也应该能够被处理。
javascript ×9
fetch-api ×3
es6-promise ×2
arrays ×1
astrojs ×1
asynchronous ×1
node-fetch ×1
node.js ×1
select ×1
typescript ×1
utf-8 ×1