【问题标题】:Ag-Grid with VueJS (vanillajs)带有 VueJS 的 Ag-Grid (vanillajs)
【发布时间】:2020-04-21 06:31:11
【问题描述】:

我正在尝试使用 VueJS 实现 Ag-Grid,但使用的是 vanillajs 版本(没有任何包或模块管理器)。

我尝试使用 umd 版本的 ag-grid (https://cdn.jsdelivr.net/npm/ag-grid-vue@22.1.1/dist/ag-grid-vue.umd.js),如下例所示。

https://jsfiddle.net/p429h0sL/

但是抛出了下面的错误;

vue.js:634 [Vue warn]: Unknown custom element: <ag-grid-vue> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

(found in <Root>)

我也尝试过this solution,但也没有运气。

你能告诉我如何进行吗?

【问题讨论】:

    标签: vue.js ag-grid ag-grid-vue


    【解决方案1】:

    我找到了解决办法。

    我需要做的第一件事,按照this solution. 中的建议添加行

    在ag-grid-vue.umd.js中加入这一行后;

    window.AgGridVue = AgGridVue;
    

    在这一行之前;

         return AgGridVue;
    }(external_commonjs_vue_commonjs2_vue_root_Vue_default.a));
    

    这样,我将 AgGridVue 变量连接到 window 对象中,结果它可以在 js 环境中全局使用。

    第二件事,我已经调用了正确的 js 文件

    <script src="ag-grid-community.min.js"></script>
    <script src="ag-grid-enterprise.min.js"></script> <!-- This line is optional, if you want to use enterprise features -->
    <script src="vue.js"></script>
    <script src="ag-grid-vue.umd.js"></script> <!-- This is the manipulated file -->
    

    然后我实例化了 Vue 和 ag-grid

    <div id="vue" style="width:100%;height:600px">
    
        <ag-grid-vue style="width:100%;height:600px" class="ag-theme-bootstrap" :column-defs="columnDefs"
            :row-data="rowData" ></ag-grid-vue>
    
    </div>
    
     <script>
    
        let vueData = {
            gridApi: null,
            rowData: [{test:1}],
            columnDefs: [{field:"test",headerName:"test"}]
        };
    
        window.onload = function () {
    
    
    
            Vue.component("ag-grid-vue", AgGridVue);
    
            let vue = new Vue({
                el: "#vue",
                data: vueData,
            })
    
        }
    </script>
    

    重要提示:您不应在 ag-grid-vue 标记 (as I explained in here) 中使用 camelCase 属性名称。相反,您必须使用 kebap-case 声明..

    这样一切正常。

    【讨论】:

    • 只需在其中添加队列就是我一直在寻找的解决方案。太棒了!
    • 谢谢你,好心人:)
    猜你喜欢
    • 2020-05-08
    • 2017-09-16
    • 2020-03-08
    • 2017-02-18
    • 2019-06-06
    • 2018-11-19
    • 2017-09-25
    • 2018-02-17
    • 2020-08-13
    相关资源
    最近更新 更多