Ruby on rails Vuejs Axios请求

Ruby on rails Vuejs Axios请求,ruby-on-rails,vue.js,axios,Ruby On Rails,Vue.js,Axios,前端 data() { return { user_data: [], user_id: '', }; }, created() { this.getUserData(); const decode = jwtDecode(localStorage.auth_token); this.user_id = decode.user_id; }, methods: { getUserData() { axios.ge

前端

 data() {
    return {
      user_data: [],
      user_id: '',
    };
  },
created() {
    this.getUserData();
    const decode = jwtDecode(localStorage.auth_token);
    this.user_id = decode.user_id;
  },
methods: {
getUserData() {
      axios.get(`http://localhost:3000/api/v1/users/${this.user_id}`) // Gets an specif book
        .then((response) => {
          this.user_data = response.data;
        });
    },
}

后台显示方法

def show
 user = User.find(params[:id])
   render json: user
 end
路线

在上面的代码中,我从令牌中获取用户id,并在我的方法
getUserData()
中从数据库中获取他的信息。但是,当我发出请求时,它不是带来特定的用户,而是给我所有注册的用户。 注意:我试图在我的
getUserData
方法中打印用户id,以查看id是否在变量
user\u id
中,并且它工作正常,但我的请求无法获得它!! 有人能帮我吗

在上面的代码中,我从令牌中获取用户id,并在方法getUserData()中从数据库中获取他的信息

代码中的顺序相反,它请求
http://localhost:3000/api/v1/users/
没有用户id

相反,它应该是:

const decode = jwtDecode(localStorage.auth_token);
this.user_id = decode.user_id;
this.getUserData();

如果可能没有用户id,则不应调用
getUserData

问题在于后端代码,您应该共享控制器的代码。您可以显示get请求处理程序吗?您的意思是什么?
const decode = jwtDecode(localStorage.auth_token);
this.user_id = decode.user_id;
this.getUserData();