老师 帮忙看下后端接口是表单提交的方式接受数据,这个地方要如何去获取到地址id传给删除接口,并且要如何传参才可以

老师 帮忙看下后端接口是表单提交的方式接受数据,这个地方要如何去获取到地址id传给删除接口,并且要如何传参才可以

https://img1.sycdn.imooc.com//climg/62526f6a09c7625504270417.jpg

我用这种方式传参是不行的

https://img1.sycdn.imooc.com//climg/62526faf09b6024409270320.jpg

https://img1.sycdn.imooc.com//climg/62526f1309bc586b08830304.jpg

<template>

  <div class="wrapper">

    <div class="top">

      <span class="iconfont top__icon"

            @click="handleBackClick">&#xe8ef;</span>

      <span class="top__title">管理收货地址</span>

      <span class="top__new"

            @click="newAddressClick">新建</span>

    </div>

    <div class="title">我的收货地址</div>


    <div class="address"

         v-for="item in info"

         :key="item.id">

      <div class="address__info">

        <span class="address__info__name">{{item.name}}</span>

        <span class="address__info__phone">{{item.phone}}</span>

      </div>

      <div class="address__tag">{{item.city}}{{item.detailAddress}}</div>

      <router-link :to="`/updateAddress/${item.id}`">

        <div class="iconfont address__icon"

             @click="updateAddressClick">&#xe8ef;</div>

      </router-link>

      <!-- <div class="iconfont adshangchudress__default"

           v-if="isDefault">默认地址</div> -->

      <div class="address__delete"

           @click="deleteAddress">删除</div>

    </div>

  </div>

  <Toast v-if="showToast"

         :message="toastMessage" />

</template>


<script>

import { useRouter } from 'vue-router'

import { reactive, toRefs } from 'vue'

import { post } from '../../utils/request'

import Toast, { useToastEffect } from '../../components/Toast.vue'


// 获取地址

const getUserAddressEffect = () => {

  const userAddress = reactive({

    info: []

  })

  const getUserAddress = async () => {

    const result = await post('/address/getUserAddress')

    if (result?.code === 1 && result?.data) {

      userAddress.info = result.data

    }

    console.log('UserAddress info:' + JSON.stringify(info))

  }

  getUserAddress()

  const { info } = toRefs(userAddress)

  return { info }

}


// 删除地址

const deleteAddressEffect = (changeToast) => {

  const deleteAddress = async () => {

    const result = await post('/address/delete', { id: '4e8eaeef56d84e69911eb8dce8353688' })

    console.log('deleteAddress result:' + result)

    changeToast('删除成功')

  }

  return { deleteAddress }

}


// 点击回退逻辑

const useBackRouterEffect = () => {

  const router = useRouter()

  const handleBackClick = () => {

    router.back()

  }

  return handleBackClick

}


// 点击新建跳转到NewAddress,封装成newAddressEffect函数

const newAddressEffect = () => {

  const router = useRouter()

  const newAddressClick = () => {

    router.push({ name: 'NewAddress' })

  }

  return { newAddressClick }

}


// 跳转到updateAddress

// const updateAddressEffect = () => {

//   const router = useRouter()

//   const updateAddressClick = () => {

//     router.push({ name: 'UpdateAddress' })

//   }

//   return { updateAddressClick }

// }


export default {

  name: 'Address',

  components: { Toast },

  setup () {

    const { showToast, toastMessage, changeToast } = useToastEffect()

    const handleBackClick = useBackRouterEffect()

    const { newAddressClick } = newAddressEffect()

    // const { updateAddressClick } = updateAddressEffect()

    const { deleteAddress } = deleteAddressEffect(changeToast)

    const { info } = getUserAddressEffect()

    return { newAddressClick, handleBackClick, deleteAddress, info, showToast, toastMessage }

  }

}

</script>


<style lang="scss" scoped>

@import "../../style/viriables.scss";

a {

  text-decoration: none;

  color: $content-fontcolor;

}

.wrapper {

  overflow-y: auto;

  position: absolute;

  top: 0;

  bottom: 0;

  left: 0;

  right: 0;

  background: #f8f8f8;

}

.top {

  position: relative;

  height: 0.44rem;

  line-height: 0.44rem;

  background: $bgColor;

  &__icon {

    font-size: 0.22rem;

    position: absolute;

    left: 0.18rem;

  }

  &__title {

    font-size: 0.16rem;

    color: $content-fontcolor;

    position: absolute;

    left: 50%;

    margin-left: -0.48rem;

  }

  &__new {

    font-size: 0.14rem;

    position: absolute;

    right: 0.18rem;

  }

}

.title {

  font-size: 0.14rem;

  color: $content-fontcolor;

  margin: 0.16rem 0 0.12rem 0.18rem;

}

.address {

  position: relative;

  box-sizing: border-box;

  margin: 0 0.18rem 0.16rem;

  // height: 1.04rem;

  background: $bgColor;

  border-radius: 0.04rem;

  padding: 0.18rem 0.16rem;

  &__info {

    font-size: 0.14rem;

    color: $light-fontColor;

    padding-bottom: 0.08rem;

    &__name {

      padding-right: 0.66rem;

    }

  }

  &__tag {

    width: 2.6rem;

    font-size: 0.14rem;

    color: $content-fontcolor;

    line-height: 0.2rem;

    padding-bottom: 0.08rem;

  }

  &__icon {

    font-size: 0.22rem;

    transform: rotate(180deg);

    position: absolute;

    right: 0.12rem;

    top: 0.12rem;

  }

  &__delete {

    text-align: right;

    font-size: 0.12rem;

  }

}

</style>



正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

3回答
好帮手慕慕子 2022-04-10 18:54:55

同学你好,对于你的问题解答如下:

1、可以参考如下思路:

(1)直接将当前地址信息传递到UpdateAddress.vue组件中

https://img1.sycdn.imooc.com//climg/6252b580090965ee10050386.jpg

(2)根据传递过来的数据设置UpdateAddress.vue中默认显示值

https://img1.sycdn.imooc.com//climg/6252b67d091b0c0312400635.jpg

(3)所有数据都是存放在info下,所以需要通过info打点调用,如下:

https://img1.sycdn.imooc.com//climg/6252b6c70950689c07130874.jpg

https://img1.sycdn.imooc.com//climg/6252b6fd09e4b7c810930666.jpg

2、在你的另一个相似提问下已经做出了解答,可以查看下http://class.imooc.com/course/qadetail/322611 

祝学习愉快~

卡布琦诺 2022-04-10 16:24:31

同学你好,可参考如下代码进行传参设置:

https://img1.sycdn.imooc.com//climg/6252943809e6d33412200849.jpg

祝学习愉快!

  • 提问者 lcy_18 #1

    老师 编辑地址想要默认进去是点击的地址信息要如何默认上去,在form表单中 这个问题可以帮忙看下吗

    2022-04-10 17:27:46
  • 提问者 lcy_18 #2

    老师 后端是表单接收参数,这种传参方式好像是有问题,要怎么修改呀

    https://img1.sycdn.imooc.com//climg/6252a3880947809c09320323.jpg

    https://img1.sycdn.imooc.com//climg/6252a3ac099e4d2f08750401.jpg

    2022-04-10 17:31:14
卡布琦诺 2022-04-10 14:15:45

同学你好,由于涉及到其他关联的代码,请同学留意右上角小铃铛的通知,老师将采用其他方式为你解答。

祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师