typescript - 如何在“vscode.window.showInformationMessage”中进行点击事件
问题描述
我有一个包含按钮的信息框,所以当我单击按钮时,我需要它在按钮单击事件中导航到网站。
我能够在信息框中添加一个按钮,但现在我对如何在“vscode.window .showInformationMessage”中进行按钮单击事件没有清楚的了解,因为我是打字稿和扩展开发的新手。所以任何人都可以请指导我?
vscode.window
.showInformationMessage("Click for more Info","Go to Help")
.then(selection => {
console.log(selection);
});
这会在调试控制台中打印“转到帮助”。这只是我尝试过的。但预期的结果是当我单击“转到帮助”按钮时,它应该导航到特定的 url(例如:https ://www.merriam-webster.com/dictionary/hep )。谁能指导我获得预期的输出,因为我不知道如何获得结果。
解决方案
您不需要“点击事件”,只需检查回调中是否已选择该选项:
let GoToHelp = 'Go to Help';
vscode.window.showInformationMessage('Click for more Info', GoToHelp)
.then(selection => {
if (selection === GoToHelp) {
vscode.env.openExternal(vscode.Uri.parse(
'https://www.merriam-webster.com/dictionary/hep'));
}
});
推荐阅读
- python - python 2打印数组,浮点格式,没有换行
- javascript - 将另一个数据添加到 firebase 数据库
- c# - ServiceStack:注销不会删除会话,因此请求经过身份验证的服务仍然有效
- laravel - Laravel 用于拣货清单的简单电子商务逻辑
- vb.net - VB.NET 打印中的边距
- forms - 在 vue js 中提交预先填写的表单
- ios - 是否针对苹果政策创建自定义 TabBar?
- regex - 使用正则表达式在 CSV 列表中的数字上设置 qoutes
- android - SDK 和 Gradle 升级后找不到 RobolectricTestRunner 类
- web-crawler - scrapy 如何在 starturl 中给出循环?