本文介绍了出现提示时,是否有一种方法可以在查询器中使用以前的答案(inquirer v6)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我想做的是在进一步询问问题时使用先前的答案.基本上,这样我就可以显示将要创建的内容的摘要并要求进行验证.
So what I want to do is use a previous answer when asking a question further down the line. Basically so that I can show a summary of what will be created and ask for a verification.
this.prompt([
{
type: 'input',
name: 'name',
message: 'What is your name?'
default: 'Jake'
},
{
type: 'confirm',
name: 'summary',
message: 'Is this information correct? Your name is:' + answers.name',
}
有没有简单的方法可以做到这一点?还是获得摘要类型的东西(列出所有以前的答案)的另一种方法?
is there an easy way to achieve this? Or another way to achieve a summary type thing that lists out all previous answers?
推荐答案
任一嵌套查询器调用:
inquirer
.prompt({
type: 'list',
name: 'chocolate',
message: "What's your favorite chocolate?",
choices: ['Mars', 'Oh Henry', 'Hershey']
})
.then(() => {
inquirer.prompt({
type: 'list',
name: 'beverage',
message: 'And your favorite beverage?',
choices: ['Pepsi', 'Coke', '7up', 'Mountain Dew', 'Red Bull']
});
});
或使用when
功能.
{
type: 'confirm',
name: 'summary',
message: 'Is this information correct? Your name is:' + answers.name,
when: function( answers ) {
// Only run if user set a name
return !!answers.name;
},
}
这篇关于出现提示时,是否有一种方法可以在查询器中使用以前的答案(inquirer v6)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!