我不知道为什么会这样,但这真的很烦人。我希望根据Express 文档下载该文件。我有下一个代码:
//in react (App.js)
download = () => {
const { images, target } = this.state;
const filename = images.find(img => img.id === target).filename;
fetch('http://localhost:3001/download', {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({filename})
})
}
//in express (server.js)
app.post('/download', (req, res) => {
var file = '../public/images/' + req.body.filename;
res.download(file, req.body.filename);
});
Run Code Online (Sandbox Code Playgroud)
文件夹结构:
-server
|-server.js
-public
|-images
|-a.jpg
|-b.jpg
-src
|-App.js
Run Code Online (Sandbox Code Playgroud)
什么也没发生,没有显示错误。有任何想法吗?
我试图想办法让Ant运行一个接受文件的.jar可执行文件,并从单个输入文件中吐出几个生成的文件.具体来说,我正在尝试生成已编译的.js文件,同时生成.map文件.
通常,命令看起来像这样:
java -jar compiler-latest --js a.js --js_output_file a.min.js --create_source_map a.js.map
Run Code Online (Sandbox Code Playgroud)
哪里:
compiler-latest 是封闭编译器jara.js 是要编译的JavaScript文件a.min.js 是编译的JavaScripta.js.map 是源地图我的Ant脚本看起来像这样:
<project name="BuildTest" default="Build" basedir=".">
<description>
HTML Build Test with Ant
</description>
<property name="src" location="../js"/>
<property name="dst" location="../build"/>
<property name="compiler" location="../compiler.jar"/>
<!--Make Dest Directory-->
<target name="-destination">
<mkdir dir="${dst}"/>
</target>
<!--Compile JS-->
<target name="Build" depends="-destination">
<!--Filesets and Mappers-->
<fileset id="sourceFiles" dir="${src}" includes="*.js"/>
<mapper id="compiledJs" type="glob" from="*.js" to="*.compiled.js"/>
<mapper id="mapJs" type="glob" from="*.js" to="*.js.map"/>
<!--Apply Everything-->
<apply executable="java" parallel="false" dest="${dst}">
<!--Closure Compiler-->
<arg …Run Code Online (Sandbox Code Playgroud) 我正在变得绝望..我尝试建立一个旋转背景图像的网站,自动调整到窗口的大小.我真的不是那么多html,css,javascript等,但我设法到目前为止,图片旋转并调整到窗口大小..但是当我缩小窗口真的很小,图片旋转出来的窗口..我希望你明白我的意思.
这是我的代码:
HTML
<div id="bgcon">
<div id="bgimg">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
html, body {
padding:0;
margin:0;
width:100%;
height:100%;
}
#bgcon {
width:100%;
height:100%;
overflow:hidden;
}
#bgimg {
content:"";
position: fixed;
width: 250%;
height: 250%;
top: -80%;
left: -80%;
z-index: -1;
overflow:hidden;
background-image: url("http://sidekickwallpapers.com/wp-content/uploads/2014/03/space-wallpapers-1920x1080-design-ideas-space-wallpapers-s3vgbbit.jpg");
-webkit-animation:spin 150s linear infinite;
-moz-animation:spin 150s linear infinite;
animation:spin 150s linear infinite;
}
}
@-moz-keyframes spin {
100% {
-moz-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
100% { …Run Code Online (Sandbox Code Playgroud) 我想将第一个函数组合到第二个函数,所以我只能调用它一次.基本上我有2个html5音频文件即时播放.一切正常.但是,如果我播放我的第一个音频,在此期间,如果我点击第二个音频,第一个音频上的暂停按钮不会更改为默认(关闭)
//First function
function toggleState(item) {
if (item.className == "play") {
item.className = "pause";
} else {
item.className = "play";
}
}
//Second function
// Play stop Music
function EvalSound(soundobj) {
var thissound = document.getElementById(soundobj);
if (thissound.paused) {
thissound.play();
} else {
thissound.pause();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用斧头Chrome扩展程序检查辅助功能,我收到了违规的单选按钮和复选框.查看W3C文档中的"aria-required",你可以在这里找到它:W3C on aria-required,既没有为使用的角色列出输入.
根据这个问题:HTML5:如何将"required"属性与"radio"输入字段一起使用,您只需要在需要时标记一个单选按钮.但是,我试图使用旧版浏览器的咏叹调并且我得到违规元素必须只使用允许的ARIA属性,说我的任何输入类型无线电或带有咏叹调要求的复选框都不允许使用 "咏叹调".
这与工具是否存在差异,HTML5所需的工作是否略有不同,或者无线电或复选框上实际上不允许使用咏叹调?
我试图用矩阵而不是精灵在JS中编写俄罗斯方块。基本上是要更好地可视化二维数组。
我通过转置块的矩阵数据然后反转行来旋转块。但是,由于块的宽度和高度不能完全填充此4x4矩阵,因此旋转会导致块移动,而不是原地旋转。
我看不到它,我已经花了超过两天的时间尝试让tetris这样简单的游戏正常工作,从头开始重新启动了几次。 ,而我唯一要做的就是井字游戏。我花了比我更多的时间。
这是完整的js代码。单击画布将旋转作品。
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
canvas.width = 400;
canvas.height = 600;
// game object
var G = {};
var current = 0;
var x = 0;
var y = 0;
//GRID
G.grid = [];
G.gridColumns = 10;
G.gridRows = 15;
for (var i = 0; i < G.gridColumns; i++) {
G.grid[i] = [];
for (var j = 0; j < G.gridRows; j++) {
G.grid[i][j] = 0;
}
}
// Array with all …Run Code Online (Sandbox Code Playgroud)我有一个javascript函数,我的游戏循环(希望)每秒60次控制输入,绘图等.
目前编码的方式似乎总是在52左右,明显低于60 fps,即使没有其他事情发生,它甚至会下降到25-30 fps
function loop() {
setTimeout(function () {
requestAnimationFrame(loop);
time += (1000 / 60);
if (time % 600 == 0) {
oldtick = tick;
tick += 1;
time = 0;
aiMovement();
combat();
}
context.clearRect(0, 0, c.width, c.height);
drawMap();
playerInput();
movePlayer();
drawEntities();
drawPopups();
var thisLoop = new Date;
var fps = 1000 / (thisLoop - lastLoop);
lastLoop = thisLoop;
context.drawImage(cursor, mouse.x, mouse.y, 16, 16);
context.fillStyle = "#ffff00";
context.fillText("FPS: " + Math.floor(fps) + " Time: " + Math.floor(time) + " …Run Code Online (Sandbox Code Playgroud) 我正在使用 Dropzone 上传文件,这是我的代码
<div>
<form id="mainDiv" class="dropzone needsclick" enctype="multipart/form-data" method="post" action="uploadFiles?type=5" role="form">
<div class="dz-message needsclick">
Drop files here or click to upload.<br />
<span class="note needsclick">(Please upload <strong>PDF, JPG, GIF, PNG, PDF</strong> files only.)</span>
</div>
</form>
</div>
<div>
<form id="recommendationDiv" class="dropzone needsclick" enctype="multipart/form-data" method="post" action="uploadFiles?type=5" role="form">
<div class="dz-message needsclick">
Drop files here or click to upload.<br />
<span class="note needsclick">(Please upload <strong>PDF, JPG, GIF, PNG, PDF</strong> files only.)</span>
</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
上传工作正常,但我想限制上传文件的类型
<script>
Dropzone.options.dropzone = {
acceptedFiles:'image/*'
};
</script>
Run Code Online (Sandbox Code Playgroud)
接受的文件似乎不起作用,它只是上传所有内容。
我正在尝试将 4 个 div 的 HTMLCollection 转换为数组,但我尝试的每种方法似乎都会导致数组被清空。
<div class="container">
<div class="shape" id="one"></div>
<div class="shape" id="two"></div>
<div class="shape" id="three"></div>
<div class="shape" id="four"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试过的方法 - 根据上一个问题:
var shapesHC = document.getElementsByClassName('shape');
//gives HTMLCollection
var shapesArrCall = [].slice.call(shapesHC);
// returns empty array
var shapesArrHC = Array.from(shapesHC);
// returns empty array
var shapesArrHCSpread = [...shapesHC];
// returns empty array
Run Code Online (Sandbox Code Playgroud)
如果有人能指出我在这里出错的地方,我将不胜感激。
谢谢。
我有一个通过插槽传递内容的组件。我正在使用渲染函数来输出内容。我使用渲染函数的原因是因为我想多次复制内容。当我使用这段代码时,一切正常:
render(createElement){
return createElement('div', {}, this.$slots.default);
}
Run Code Online (Sandbox Code Playgroud)
当传递的数据发生变化时,输出也会发生变化。
但是,由于我想复制插槽内容,所以我现在尝试这样做:
return createElement(
'div', {},
[
createElement('div', { }, this.$slots.default),
createElement('div', { }, this.$slots.default)
]
)
Run Code Online (Sandbox Code Playgroud)
现在的问题是,当槽内容从组件外部更改时,只有第二个 div 中的内容会更新,第一个 div 中的内容保持不变。
我在这里错过了什么吗?