web-applications - Vue 3.0.0 PrimeVue 3.3.5 单击 DataTable 中的按钮时出现 $options.editCategories 错误
问题描述
I. 有以下我正在为应用程序编写的组件。该组件在未完成的应用程序中用于 PrimeVues TabVue。我试图调整 CRUD DataTable 示例,但是 wgen 我单击编辑项(或删除项)按钮我收到 $options.editCategory is not a function error in the browser console。显然我在这里遗漏了一些东西,但不知道是什么。任何建议,将不胜感激。
模板部分包括
<DataTable ref="dt" :value="categories" :dataKey="id" stripedRows>
<Column field="id" header="ID" class="p-col-1"></Column>
<Column field="name" header="Name" class="p-col-10"></Column>
<Column> :exportable="false">
<template #body="slotProps">
<Button
icon="pi pi-pencil"
class="p-button-rounded p-button-success p-mr-2"
@click="editCategory(slotProps.data)"
/>
<Button
icon="pi pi-trash"
class="p-button-rounded p-button-danger p-mr-2"
@click="deleteCategory(slotProps.data)"
/>
</template>
</Column>
</DataTable>
<!-- Add new category button -->
<div class="p-d-flex p-jc-end p-mt-3">
<Button label="Add" @click="openAddDlg" />
</div>
<!-- Dialog boxes -->
<Dialog header="Add New Category" :visible="addCategory" :style="{ width: '500px'}" :modal="true">
<div class="p-fluid p-grid">
<div class="p-field p-col-12 p-mt-3">
ID: {{ currCategory.id }}
</div>
<div class="p-field p-col-10 p-mt-3">
<span class="p-float-label">
<InputText id="category" type="text" v-model="currCategory.name" />
<label for="category">Category Name</label>
</span>
</div>
</div>
<template #footer>
<div class="p-d-flex p-jc-end p-mt-3">
<Button label="Cancel" class="p-button-outlined" @click="closeAddDlg" />
<Button label="Save" @click="saveNewCategory" />
</div>
</template>
</Dialog>
脚本部分包含
import DataTable from 'primevue/datatable/sfc'
import Column from 'primevue/column/sfc'
import Button from 'primevue/button/sfc'
import Dialog from 'primevue/dialog/sfc'
import InputText from 'primevue/inputtext/sfc'
export default {
name: 'CategorySettings',
components: { DataTable, Column, Button, Dialog, InputText },
data() {
return {
categories: [],
currCategory: null,
addCategory: false,
editCategory: false,
deleteCategory: false
}
},
methods: {
openAddDlg() {
let id = 1
if (this.categories.length) {
id = this.categories[this.categories.length - 1].id + 1
}
this.currCategory = { id: id, name: '' }
this.addCategory = true
},
closeAddDlg() {
this.addCategory = false
},
saveNewCategory() {
if (this.currCategory.name !== '') {
this.categories.push(this.currCategory)
}
this.addCategory = false
},
editCategory(category) {
this.currCategory = {...category}
},
deleteCategory(category) {
}
}
}
Sorry about the formatting of the script section. It was formatted properly when I pasted it in.
解决方案
已解决:即使我认为上下文不同,简单地重命名函数 editCategory 和 deleteCategory 也会导致名称冲突。我的建议是确保您的回调函数在其他所有内容中都是唯一命名的。
推荐阅读
- mysql - MySQL 2 列不在(一项数组)
- javascript - 无法在 javaScript 的嵌套 if 语句中调用全局变量
- azure-devops - Azure DevOps Pipeline CMake 与 MSVC 和 NMake
- java - 未指定 Java 客户端 Web 服务器错误文件路径
- angular - 如何发出 Observable 然后限制订阅
- python - 将多维字典(fetchall-type)转换为多维列表
- javascript - Java-script:尝试向我的变量添加小数位
- io - COBOL 记录未写入文本文件
- python - “实体”对象没有值“宽度”
- laravel - 同一页面上的两个表单 Laravel