首页 > 解决方案 > 如何从 vs 代码扩展 api 显示是/否对话框

问题描述

我正在开发 vscode 中的扩展,在某些时候我需要向用户确认某些代码操作。
我想提示一个对话框并得到是或现在,我无法在 vscode api 中找到任何方法,如确认或警报,你能帮忙吗

标签: visual-studio-codevscode-extensions

解决方案


好像您正在寻找vscode.window.showInformationMessage女巫需要两个参数message...items(有关更多信息,请参阅API 参考。可以在此示例中使用:

vscode.window
  .showInformationMessage("Do you want to do this?", "Yes", "No")
  .then(answer => {
    if (answer === "Yes") {
      // Run function
    }
  })

推荐阅读