个人网站的后台文章管理功能

项目场景:

实现一个能够前后端交互的后台文章管理功能


问题描述

最开始思路出错,仅做到了dom的删除

let target1
noBtn.onclick =deletePop.onclick=function(){
        popUps.style.display="none"
}
yesBtn.onclick =function (){
        target1.parentNode.remove() 
        popUps.style.display = "none"
}
const tBody =document.querySelector('.blog-list tbody') 
tBody.onclick = function(e){ 
        target1 =e.target.parentNode 
        let target =etarget 
console.log(target);
console.log(target.parentNode);
if(target.classList.contains('delete')){ 
        popUps.style.display = "block"
        return target1}

解决方案:

运用事件委托和自定义属性,向后端传需要删除的文章id,再次渲染。从而实现功能

yesBtn.onclick = function () {

    getUserId()

    function getUserId() {

        axios.get('/admin/deleteBlog', {

          params: {

            id: userId

          }

        }).then(res => {

          if (res.data == "success") {

            fetchData()

          }

        })

      }

    popUps.style.display = "none"

  }

  const tBody = document.querySelector('.blog-list tbody')

  tBody.onclick = function (e) {

    let target = e.target

    userId = target.getAttribute('user-id')

    console.log(userId);

    if (target.classList.contains('delete')) {

      popUps.style.display = "block"

      return userId

    } else if (target.classList.contains('edit')) {

      window.location.href = './post-blog.html';

    }

  }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值