为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 vue js 传递和检索 id?

如何使用 vue js 传递和检索 id?

C#
人到中年有点甜 2023-07-09 15:14:24
我正在尝试将 id 从 1 vue 传递到另一个 vue 并获取我的 api 服务的数据。我能够从第一个 vue (ClientListing.vue) 传递 id,但不知何故我的第二个 vue (Client.vue) 无法检索 id。我的客户列表.vue    <th scope="row" v-on:click="rowClicked(row)" style="cursor: pointer">        <div class="media align-items-center" @click="showClient(row)">          <a class="avatar rounded-circle mr-3">              <img alt="Image placeholder" :src="row.customerTypeIcon">          </a>          <div class="media-body">              <span class="name mb-0 text-sm">{{row.name}}</span>          </div>       </div>    </th>methods: {   showClient(item) {   router.push({ path: 'Clients/client', query: { id: item.id } });   }}我的客户端.vuemounted: function () {   CifRepository   .getCustomerDetails(this.$route.query)   .then(response => {      this.model = response.data.Results;   }).catch(error => {   console.log(error)   this.errored = true}).finally(() => this.loading = false);}getCustomerDetails(id) {   return Repository.get("/api/Accounts/GetCustomerDetails");}我的 api 服务 - AccountsController[HttpGet("GetCustomerDetails")]public async Task<CustomerListingDto> GetCustomerDetails(long id){   CustomerServiceModel customers = await   _accountService.GetCustomerDetailsByCustomerId(id);   return _mapper.Map<CustomerListingDto>(customers);}我的 AccountController/GetCustomerDetails 不断获取 0/null 值,并且无法从 ClientListing.vue 获取 id 传递
查看完整描述

1 回答

?
吃鸡游戏

TA贡献1829条经验 获得超7个赞

它应该this.$route.query.id代替this.$route.query


mounted: function () {

  CifRepository

  .getCustomerDetails(this.$route.query.id)

  .then(response => {

    this.model = response.data.Results;

  })

  .catch(error => {

    console.log(error)

    this.errored = true

  })

  .finally(() => this.loading = false);

}


getCustomerDetails(id) {

   return Repository.get("/api/Accounts/GetCustomerDetails/" + id);

}

我不确定 C# 部分,但可能是


[HttpGet("GetCustomerDetails/${id}")]

public async Task<CustomerListingDto> GetCustomerDetails(long id)

{


   CustomerServiceModel customers = await

   _accountService.GetCustomerDetailsByCustomerId(id);


   return _mapper.Map<CustomerListingDto>(customers);

}


查看完整回答
反对 回复 2023-07-09
  • 1 回答
  • 0 关注
  • 121 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信