执行功能在按钮上单击Ag -Grid表单元格 - VUEJS/NUXTJS
我已经在NUXTJS应用程序上安装了AG-Grid社区插件。一切都很好,但是我在如何使我的按钮上的按钮上执行了在方法上定义的功能。
这是我到目前为止所做的事情:
index.vue
<template>
<div>
<ag-grid-vue style="width: 100%; height: 500px;" class="ag-theme-alpine"
:columnDefs="columnDefs" @grid-ready="onGridReady" :defaultColDef="defaultColDef"
:rowData="rowData" :rowHeight="rowHeight">
</ag-grid-vue>
</div>
</template>
<script>
export default {
data() {
return {
columnDefs: [{
field: 'scope',
resizable: true,
sortable: true,
headerName: 'Name',
},
{
field: 'scope',
resizable: true,
sortable: true,
headerName: 'Age',
},
{
field: 'scope',
resizable: true,
sortable: true,
headerName: 'Delete',
cellRenderer(params) {
return '<button @click="deleteLog(id)" type="button">Delete</button>'
}
}]
....
}
}
},
async deleteLog(id) {
if (confirm("Do you really wish to delete this person?")) {
const token = localStorage.getItem('token');
await this.$axios.patch(`/v1/delete/${id}/`, {
headers: {
Authorization: `Bearer ${token}`
},
deleted: true
}).then(() => {
this.$router.app.refresh()
}).catch(error => {
this.errors = error.response.data.errors;
})
}
}
</script>
我的表与按钮正确渲染,但我无法选择或单击按钮执行我的DeletElog函数。任何解决方案的帮助将不胜感激。
I have installed AG-Grid community plugin on my NuxtJs app. Everything is working great but am getting stuck on how to make my buttons on cell-renderer execute the functions defined on methods.
Here is what I have done so far:
index.vue
<template>
<div>
<ag-grid-vue style="width: 100%; height: 500px;" class="ag-theme-alpine"
:columnDefs="columnDefs" @grid-ready="onGridReady" :defaultColDef="defaultColDef"
:rowData="rowData" :rowHeight="rowHeight">
</ag-grid-vue>
</div>
</template>
<script>
export default {
data() {
return {
columnDefs: [{
field: 'scope',
resizable: true,
sortable: true,
headerName: 'Name',
},
{
field: 'scope',
resizable: true,
sortable: true,
headerName: 'Age',
},
{
field: 'scope',
resizable: true,
sortable: true,
headerName: 'Delete',
cellRenderer(params) {
return '<button @click="deleteLog(id)" type="button">Delete</button>'
}
}]
....
}
}
},
async deleteLog(id) {
if (confirm("Do you really wish to delete this person?")) {
const token = localStorage.getItem('token');
await this.$axios.patch(`/v1/delete/${id}/`, {
headers: {
Authorization: `Bearer ${token}`
},
deleted: true
}).then(() => {
this.$router.app.refresh()
}).catch(error => {
this.errors = error.response.data.errors;
})
}
}
</script>
My table is rendered properly with the button but I can't select or click the button to execute my deleteLog function. Any help to resolve will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过创建一个按钮单元格组件来解决问题,并使用vue.extend
组件/btn-cell-renderer.vue
然后,我导入了该组件并在索引上增加了很少的更改。 vue
index.vue
I was able to resolve the issue by creating a button cell renderer component and extend it with Vue.extend
components/btn-cell-renderer.vue
Then I imported the component and added few changes on my index.vue
Index.vue