简体   繁体   English

在Vue.js中传递参数

[英]Passing Parameter in Vue.js

I am trying to pass a parameter in my Vue.js project, but having no luck. 我正在尝试在Vue.js项目中传递参数,但没有运气。 The goal is when I select a user from a list, it should route to that specific user's profile as localhost:61601/Profile/"lastName" 目的是当我从列表中选择一个用户时,它应该路由到该特定用户的配置文件,例如localhost:61601 / Profile /“ lastName”

Here is my method when I click next to the users name: 这是我单击用户名旁边的方法:

 editItem(lastName) {
    this.$router.push({ name: 'GetInquiry', params: { lastName: lastName } })
    this.$http.get('http://localhost:61601/api/' + 'GetInquiry/' + { lastName : lastName })
  },
  async GetAllInquiries() {
    this.loading = true

    try {
      this.records = await api.GetAllInquiries()
    } finally {
      this.loading = false
    }
  },

As of right now, I am just passing the lastName, but eventually, it will pass a unique id. 截至目前,我只是传递了lastName,但最终它将传递一个唯一的ID。

Here is the test Profile Page, Here I am just trying to get that users information to display to test the page. 这是测试配置文件页面,在这里我只是想让用户信息显示出来以测试页面。 So if everything works, the users firstName should display: 因此,如果一切正常,则用户firstName应该显示:

<template>
 <div class="Profile">
  <div class="container">
   <div class="row">
    <template slot="items" slot-scope="records">
      <h1> Student Name: {{ records.items.firstName }}</h1>
    </template>
  </div>
</div>

 <script>
   import api from '../../store/api.js'

export default {
data() {
  return {
    records: {},
  }
},

async created() {
  this.GetInquiriesByUser()
},
methods: {
  async GetInquiriesByUser() {
    this.loading = true

    try {
      this.records = await api.GetInquiriesByUser()
    } finally {
      this.loading = false
    }
  },
}
}
</script> 

Here is my routes.js 这是我的routes.js

{
path: '/Profile/:lastName',
name: 'GetInquiry',
component: Profile
}

When i open dev tools on chrome, I get localhost:61601/api/GetInquiry/[object%20Object] 当我在Chrome上打开开发工具时,我得到了localhost:61601 / api / GetInquiry / [object%20Object]

Im using .netcore api for the backend, which gets results as expected, just cannot seem to get it up on my frontend. 我在后端使用.netcore api,该API获得预期的结果,但似乎无法在我的前端获得它。 If someone can help me and point me to the right direction that would be awesome. 如果有人可以帮助我,并指出正确的方向,那将很棒。 Please do let me know if anyone needs more details. 如果有人需要更多详细信息,请告诉我。

You are passing an object on the vue-resource instead of the value. 您正在vue资源上传递一个对象而不是值。

Just pass directly the lastname into the route and it should work as fine. 只需将姓氏直接传递到路线中,它就可以正常工作。

this.$http.get(`http://localhost:61601/api/GetInquiry/${lastName}`);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM