吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 721|回复: 10
收起左侧

[求助] 求解,在学习数据增删改的时候报错了

[复制链接]
ahehaoyu 发表于 2022-8-27 16:47
这个报错是什么原因呢,跟着B站UP视频操作的,一模一样的代码。为啥我的会报错
Snipaste_2022-08-27_15-50-06.png

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

hanbangze 发表于 2022-8-27 17:15
把整个代码拿出来看看,信息太局限
 楼主| ahehaoyu 发表于 2022-8-27 17:22
本帖最后由 ahehaoyu 于 2022-8-27 17:25 编辑
hanbangze 发表于 2022-8-27 17:15
把整个代码拿出来看看,信息太局限

[JavaScript] 纯文本查看 复制代码
<template>
    <div>
        <n-button @click="showaddModel = true" type="info">添加</n-button>
        <n-table :bordered="false" :single-line="false">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>名称</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(category, index) in categorylist">
                    <td>{{ category.id }}</td>
                    <td>{{ category.name }}</td>
                    <td>
                        <n-space>
                            <n-button @click="toupdate(category)" type="primary">修改</n-button>
                            <n-button @click="deletecategory(category)" type="warning">删除</n-button>
                        </n-space>
                    </td>
                </tr>
            </tbody>
        </n-table>

        <n-modal v-model:show="showaddModel" preset="dialog" title="Dialog">
            <template #header>
                <div>添加分类</div>
            </template>
            <div>
                <n-input v-model:value="addcategory.name" type="text" placeholder="请输入名称" />
            </div>
            <template #action>
                <div>
                    <n-button @click="add">提交</n-button>
                </div>
            </template>
        </n-modal>
        <n-modal v-model:show="showupdateModel" preset="dialog" title="Dialog">
            <template #header>
                <div>修改分类</div>
            </template>
            <div>
                <n-input v-model:value="updatecategory.name" type="text" placeholder="请输入名称" />
            </div>
            <template #action>
                <div>
                    <n-button @click="update">提交</n-button>
                </div>
            </template>
        </n-modal>
    </div>
</template>

<script setup>

import { AdminStore } from '../../stores/AdminStore'
import { ref, reactive, inject, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router';
const router = useRouter()
const route = useRoute()

const axios = inject("axios")
const message = inject("message")
const dialog = inject("dialog")
const adminStore = AdminStore()

const showaddModel = ref(false)
const showupdateModel = ref(false)

const categorylist = ref([])
const addcategory = reactive({
    name: ""
})

const updatecategory = reactive({
    id: 0,
    name: ""

})

onMounted(() => {
    loadDatas()
})
const loadDatas = async () => {
    let res = await axios.get("/category/list")
    categorylist.value = res.data.rows
}
const add = async () => {
    let res = await axios.post("/category/_token/add", { name: addcategory.name })
    if (res.data.code == 200) {
        loadDatas()
        message.info(res.data.msg)
    } else {
        message.error(res.data.msg)
    }
    showaddModel.value = false;
}
const toupdate = async (category) =>{
    showupdateModel.value = true
    updatecategory.id = category.id
    updatecategory.name = category.name
}
const update = async () => {
    //let res = await axios.put("/category/_token/update", { id: updatecategory.id, name: updatecategory.name })
    let res = await axios.put("/category/_token/update", { id: updatecategory.id, name: updatecategory.name })
    if (res.data.code == 200) {
        loadDatas()
        message.info(res.data.msg)
    } else {
        message.error(res.data.msg)
    }
    showupdateModel.value = false
    }

const deletecategory = async (category) => {
    dialog.warning({
        title: '警告',
        content: '是否要删除',
        positiveText: '确定',
        negativeText: '取消',
        onPositiveClick: async () => {

            let res = await axios.delete(`/category/_token/delete?id=${category.id}`)
            if (res.data.code == 200) {
                loadDatas()
                message.info(res.data.msg)
            } else {
                message.error(res.data.msg)
            }
        },
        onNegativeClick: () => { }
    })
}
</script>

<style lang="scss" scoped>
</style>
 楼主| ahehaoyu 发表于 2022-8-27 17:25
hanbangze 发表于 2022-8-27 17:15
把整个代码拿出来看看,信息太局限

代码已经发出来了 在update哪里会报错
hanbangze 发表于 2022-8-27 17:29
ahehaoyu 发表于 2022-8-27 17:25
代码已经发出来了 在update哪里会报错

目前没找到,我再看看
hanbangze 发表于 2022-8-27 17:34
ahehaoyu 发表于 2022-8-27 17:25
代码已经发出来了 在update哪里会报错

非常奇怪,我发现不了,我水平有限,再找找别人吧
 楼主| ahehaoyu 发表于 2022-8-27 17:44
hanbangze 发表于 2022-8-27 17:34
非常奇怪,我发现不了,我水平有限,再找找别人吧

增加 删除 查询都没有问题 ,就改不了
kw2022 发表于 2022-8-27 18:01
看着好像没毛病。。。。
icodeme 发表于 2022-8-27 18:23
47行 id,name能正确获取到吗,拼接后的SQL语句是否正确?
我爱总攻大人 发表于 2022-8-27 19:58
看你报错信息,可能是字符串和JSON转换的问题
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-15 18:44

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表