我正在创建一个 WebExtension,我需要在我的 content.js 中使用选择菜单库。它有系绳依赖项,所以我安装了:
npm install tether
npm install selection-menu
然后在我的代码中我写:
import * as Tether from 'tether'
import SelectionMenu from 'selection-menu'
...
this.selection_menu = new SelectionMenu({
container: document.body,
content: '<button> click me </button>',
onselect: function(e) {
this.menu.innerHTML = 'Selection length: ' + this.selectedText.length;
}
});
但是当我选择文本时,出现错误:
VM1492:23 Uncaught ReferenceError: Tether is not defined
at i.show (<anonymous>:23:2899)
at <anonymous>:23:4192
如何解决此错误?