axios从Vue获得对特定Rails控制器动作的请求

问题描述 投票:0回答:1

我想从agent.vue文件向agents_controller中的download_profile方法获取获取请求。我无法弄清楚如何向特定的download_profile方法发出请求。请帮助我解决此问题。

我需要在downloadProfile方法中的axios请求中提及特定方法。

<template>
  <v-card class="mb-12">
    <v-form :model='agent'>
     <a href="#" @click.prevent='downloadProfile(agent)'>
       <span>Download</span>
     </a>
    </v-form>
   </div>
  </v-card>
</template>


<script>

  export default {
    data: function () {
     return {
      agent: {
        id: '',
        name: ''
      }
     }
    }
    methods: {
        downloadProfile(agent) {
          this.$axios.get('/agent.json', { agent: this.agent })
        },
     }
  }
</script>

agents_controller.rb

def download_profile
  puts params
end

routes.rb

get :agent, to: 'agent#download_profile', constraints: ->(req) { req.format == :json }
javascript ruby-on-rails vue.js ruby-on-rails-5
1个回答
0
投票

您可以尝试在您的get请求中添加“ responseType:'arraybuffer'”

© www.soinside.com 2019 - 2024. All rights reserved.