Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Yeoman复制功能不支持';提示后不能工作_Javascript_Yeoman - Fatal编程技术网

Javascript Yeoman复制功能不支持';提示后不能工作

Javascript Yeoman复制功能不支持';提示后不能工作,javascript,yeoman,Javascript,Yeoman,我正在摆弄约曼,想为一个简单的html5样板编写我的第一个生成器。我的问题是,我的生成器中的两个函数单独运行良好,但不能一起工作,我不知道为什么。我检查了约曼页面上的一些发电机,但我不知道我做错了什么。我希望你能帮助我。这是我的代码: 'use strict'; var generators = require('yeoman-generator'); var yosay = require('yosay'); module.exports = generators.Base.extend({

我正在摆弄约曼,想为一个简单的html5样板编写我的第一个生成器。我的问题是,我的生成器中的两个函数单独运行良好,但不能一起工作,我不知道为什么。我检查了约曼页面上的一些发电机,但我不知道我做错了什么。我希望你能帮助我。这是我的代码:

'use strict';
var generators = require('yeoman-generator');
var yosay = require('yosay');

module.exports = generators.Base.extend({

  initializing: function(){
    this.log(yosay("\'Allo \'allo I will create your HTML5 Boilerplate..."));
  },

  prompting: function() {
    var done = this.async();
    this.prompt({
      type: 'input',
      name: 'name',
      message: 'Your project name',
      //Defaults to the project's folder name if the input is skipped
      default: this.appname
    }, function(answers) {

      this.props = answers
      this.log(answers.name);
      done();
    }.bind(this));
  },

  writing: function(){
    this.fs.copyTpl(
      this.templatePath('_page/_index.html'),
      this.destinationPath('index.html'),
      { title: "answers.name" }
    );
  },
});

提前谢谢

尝试使用Promissions版本的提示功能,如所示

示例:

prompting: function() {
    return this.prompt({
      type: 'input',
      name: 'name',
      message: 'Your project name',
      //Defaults to the project's folder name if the input is skipped
      default: this.appname
    }).then(function(answers) {
      this.props = answers
      this.log(answers.name);
    }.bind(this));
  },
变化:

  • this.prompt()之前添加
    return

  • 更改此.prompt(提示、回调)
    这个.prompt(提示)。然后(回调)


  • 谢谢,但这不起作用:-(…控制台出现错误“Object[Object Object]没有“then”方法”…我已尝试更新yeoman生成器,但错误依然存在。我不太习惯承诺,但为什么其他生成器不使用承诺?没有承诺的旧语法仍然有效它可能比新方法更不可靠。为了更好地了解发生了什么,您可以尝试记录
    t他的
    到控制台-
    这个
    应该引用整个生成器对象。如果它没有引用,那可能就是问题的根源。