We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
前些日子在用yeoman自定义自己的脚手架的时候忽然对终端交互产生了兴趣。 这些下拉框,单选框,复选框到底是怎么做的呢? 后来了解到yeoman用的是**inquirer.js**。
npm install inquirer
var inquirer = require("inquirer"); var validator = require("validator"); // 我使用了validator校验手机号 var questions = [ //是否类型 { type: "confirm", name: "sex", message: "Are you male?", default: false }, // 输入类型,添加校验 { type: "input", name: "phone", message: "What's your phone number", validate: function (value) { return validator.isMobilePhone(value, 'zh-CN') ? true : "Please enter a valid phone number"; } }, //select下拉选项 { type: "list", name: "weight", message: "How much is your weight", choices: ["Large", "Middle", "Small"], filter: function (value) { return value.toLowerCase(); } }, ]; inquirer.prompt(questions, function (answers) { console.log(answers); });
The text was updated successfully, but these errors were encountered:
No branches or pull requests
起因
前些日子在用yeoman自定义自己的脚手架的时候忽然对终端交互产生了兴趣。
这些下拉框,单选框,复选框到底是怎么做的呢?
后来了解到yeoman用的是**inquirer.js**。
使用方法
1. 安装
2. 使用
3. 结果
The text was updated successfully, but these errors were encountered: