如何将 ag-grid 实施到 nuxt.js
How to implement ag-grid into nuxt.js
如何通过 nuxt.config
文件集成 ag-grid
与 nuxt.js
一起工作?
我遇到的错误:
commons.app.js:16278 Uncaught TypeError: Cannot read property '_init' of null
at AgGridVue (commons.app.js:16278)
at Function.Vue.use (commons.app.js:16233)
at Module../plugins/ag-grid.client.js (app.js:5186)
at webpack_require (runtime.js:791)
at fn (runtime.js:151)
at Module../.nuxt/index.js (app.js:1997)
at webpack_require (runtime.js:791)
at fn (runtime.js:151)
at Module. (app.js:236)
at 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"
],
要将 table 加载到的文件:
<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>
在文件"ag-grid.client.js"中,您不能使用Vue.use添加组件,您需要使用Vue.component,它会全局注册:
import Vue from 'vue'
import { AgGridVue } from 'ag-grid-vue'
Vue.component('ag-grid-vue', AgGridVue)
然后你不需要设置标签“”。
如何通过 nuxt.config
文件集成 ag-grid
与 nuxt.js
一起工作?
我遇到的错误:
commons.app.js:16278 Uncaught TypeError: Cannot read property '_init' of null
at AgGridVue (commons.app.js:16278)
at Function.Vue.use (commons.app.js:16233)
at Module../plugins/ag-grid.client.js (app.js:5186)
at webpack_require (runtime.js:791)
at fn (runtime.js:151)
at Module../.nuxt/index.js (app.js:1997)
at webpack_require (runtime.js:791)
at fn (runtime.js:151)
at Module. (app.js:236)
at 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"
],
要将 table 加载到的文件:
<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>
在文件"ag-grid.client.js"中,您不能使用Vue.use添加组件,您需要使用Vue.component,它会全局注册:
import Vue from 'vue'
import { AgGridVue } from 'ag-grid-vue'
Vue.component('ag-grid-vue', AgGridVue)
然后你不需要设置标签“”。