【问题标题】:How to implement ag-grid into nuxt.js如何在 nuxt.js 中实现 ag-grid
【发布时间】:2019-11-10 08:48:27
【问题描述】:

如何通过nuxt.config文件集成ag-gridnuxt.js一起工作?

我得到的错误:

commons.app.js:16278 未捕获的类型错误:无法读取 null 的属性“_init”
在 AgGridVue (commons.app.js:16278)
在 Function.Vue.use (commons.app.js:16233)
在 Module../plugins/ag-grid.client.js (app.js:5186)
webpack_require (runtime.js:791)
在 fn (runtime.js:151)
在 Module../.nuxt/index.js (app.js:1997)
webpack_require (runtime.js:791)
在 fn (runtime.js:151)
在模块。 (app.js:236)
在 Module../.nuxt/client.js (app.js:1308)

ag-grid.client.js:

import Vue from "vue";
import { AgGridVue } from "ag-grid-vue";

Vue.use(AgGridVue);

nuxt.config.js:

 plugins: [
"@/plugins/element-ui",
"@/plugins/tooltip",
"@/plugins/calendar",
"@/plugins/ag-grid.client.js"
],

要加载表格的文件:

<template>
  <div class="flex h-full">
      <no-ssr>

    <ag-grid-vue style="width: 500px; height: 500px;"
                 class="ag-theme-balham"
                 :columnDefs="columnDefs"
                 :rowData="rowData">
    </ag-grid-vue>
</no-ssr>

  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      columnDefs: null,
      rowData: null
    };
  },
  beforeMount() {
    this.columnDefs = [
      { headerName: "Make", field: "make" },
      { headerName: "Model", field: "model" },
      { headerName: "Price", field: "price" }
    ];

    this.rowData = [
      { make: "Toyota", model: "Celica", price: 35000 },
      { make: "Ford", model: "Mondeo", price: 32000 },
      { make: "Porsche", model: "Boxter", price: 72000 }
    ];
  }
};
</script>

【问题讨论】:

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


    【解决方案1】:

    在“ag-grid.client.js”文件中,不能使用Vue.use添加组件,需要使用Vue.component,它会全局注册:

    import Vue from 'vue'
    import { AgGridVue } from 'ag-grid-vue'
    
    Vue.component('ag-grid-vue', AgGridVue)
    

    然后你就不需要设置标签“”了。

    【讨论】:

    • 谢谢!这确实解决了我面临的问题!
    猜你喜欢
    • 2023-03-03
    • 2018-10-03
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 2019-06-11
    • 1970-01-01
    • 2016-06-23
    • 2019-03-17
    相关资源
    最近更新 更多