使用 Quasar bex 将 Vue 组件注入网页

Inject Vue Component into web page using Quasar bex

我正在使用 quasar bex 构建一个浏览器扩展,并且 我想在加载的网页中显示一个vue组件

我已经尝试使用内容脚本挂钩在网页中添加原始 html 和 css

但我想从我的 src/components 文件夹中添加一个组件,该文件夹也使用 quasar 组件,如 q-btn 等。

有什么办法可以实现吗!

谢谢!

好的,我已经设法解决了 我正在编写解决方案,所以可能其他人会发现它有用 我使用 iframe 将我的组件或页面注入到加载的网页中

首先我创建了一条新路线,比如test in routes.js like

{
  name: "test",
  path: "/test",
  component: () => import("pages/test.vue"),
},

然后我创建了一个 iframe 并加载了那个特定的路由 在内容中-script.js喜欢

function createIframe() {
  const iframe = document.createElement("iframe");
  iframe.width = "220px";
  iframe.height = "220px";

  Object.assign(iframe.style, {
    position: "fixed",
    border: "none",
    zIndex: "10000",
  });

  // load that specific page 
  iframe.src = chrome.runtime.getURL("www/index.html#test");

  return iframe;
}

您可以设置 iframe 的宽度和高度以及您可能需要的其他内容 然后你可以将它作为一个元素注入到任何地方,如

document.body.prepend(createIframe());

我们开始了! :)