是否可以在没有构建器的情况下将 ag-grid 与 vue 一起使用?

Is it possible to use ag-grid with vue without a builder?

特别是,是否可以编译 ag-grid-vue 组件的 typescript 源代码,然后将其包含在常规 html 文件中?

我想通了:

下载ag-grid源代码,进入packages/ag-grid-vue目录,执行npm installnpm run build。这会将已编译的 javascript 模块放在 dist 目录中,无需构建系统即可使用。

我确实必须稍微修改构建的 javascript 才能将 AgGridVue 对象放入全局命名空间,因为我没有使用模块加载器。

编辑: 要将 AgGridVue 放入全局命名空间,请将 window.AgGridVue = AgGridVue; 添加到 returns AgGridVue in ag-grid-vue.umd.js

函数的末尾

我找到了一种无需修改源代码即可执行此操作的方法。在 ag-grid-vue.umd.js 的顶部附近,您可以看到该模块执行此操作:

root["ag-grid-vue"] = factory(root["Vue"], root["agGrid"]);

这里,"root"就是window,工厂调用的结果就是你想要的。但是由于破折号,您无法直接访问它。但是您可以使用字典语法(或任何名称):

let agVueObj = window["ag-grid-vue"];
//The component is a field on this object:
let AgGridVue = agVueObj.AgGridVue;
//Then register it as a component in your Vue instance:
//components: { AgGridVue }

而且您应该可以使用 <ag-grid-vue> 标签。