亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 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 關注
  • 143 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號