添加导入后,我的Chrome扩展程序便停止工作

时间:2019-12-16 02:03:45

标签: javascript google-chrome-extension

当前代码有效,当单击按钮时将发出警报,但是如果我将myAlert移到另一个文件中并导入它,它将停止工作。任何人都知道发生了什么事吗?

manifest.json

{
  "name": "Getting Started Example",
  "version": "1.0",
  "description": "Build an Extension!",
  "browser_action": {
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

popup.html

<!DOCTYPE html>
<html>
  <head>
    <style>
      button {
        height: 30px;
        width: 30px;
        outline: none;
      }
    </style>
  </head>
  <body>
    <button id="changeColor"></button>
    <script type="module" src="popup.js"></script>
  </body>
</html>

popup.js

// import { myAlert } from "./alert";
function myAlert() {
    alert("hello");
}

let changeColor = document.getElementById('changeColor');
changeColor.onclick = myAlert;

0 个答案:

没有答案