需要给函数传一个参数,但是这种形式的interval不起作用
playGame() {
this.interval = setInterval(this.gameService.startLife(this.field),
this.timeLeft)
}
需要给函数传一个参数,但是这种形式的interval不起作用
playGame() {
this.interval = setInterval(this.gameService.startLife(this.field),
this.timeLeft)
}
运行 gulp 时在 linux ubuntu 16.04 上工作时出错
> template@1.0.0 gulp /media/Data/GitHub/template
> gulp
sh: 1: gulp: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! template@1.0.0 gulp: `gulp`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the template@1.0.0 gulp script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/igor/.npm/_logs/2018-04-26T14_57_52_348Z-debug.log
igor@Usus:/media/Data/GitHub/template$
下面是我的 gulp 文件
var gulp = require('gulp');
var concat = require('gulp-concat');
//var uglify = require('gulp-uglify');
let uglify = require('gulp-uglify-es').default;
var sourcemaps = require('gulp-sourcemaps');
var cssmin = require('gulp-cssmin');
var del = require('del');
var paths = {
scripts: ['js/**/*.js'],
styles: ['css/**/*.css']
};
gulp.task('clean', function() {
return del(['build']);
});
gulp.task('css', function() {
return gulp.src(paths.styles)
.pipe(concat('main.min.css'))
.pipe(sourcemaps.init())
.pipe(cssmin())
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/css'));
});
gulp.task('scripts', function() {
return gulp.src(paths.scripts)
.pipe(uglify())
.pipe(sourcemaps.init())
.pipe(concat('main.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/js'))
});
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts']);
gulp.watch(paths.styles, ['css']);
});
面对这样的问题,Chrome 给出了以下错误。
无法加载http://localhost:3000/cars:对预检请求的响应未通过访问控制检查:“Access-Control-Allow-Origin”标头的值“null”不等于提供的来源. 因此,Origin 'null' 不允许访问。
这是我与服务器联系的请求:
getData () {
const url = "http://localhost:3000/cars";
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader('Content-type','application/json; charset=utf-8');
xhr.onload = function () {
const response = JSON.parse(xhr.responseText);
if (xhr.status == "200") {
return response;
} else {
console.error(response);
}
};
xhr.send();
}