axios成功发布后重定向

时间:2017-11-10 03:44:41

标签: redirect vue.js axios vue-router vuex

Axios,出于某种原因,在我的帖子请求之后重定向(不重定向,但将所有数据作为查询参数放置,从而导致重定向)。

这是代码,非常简单:

  actions: {
    createProject (context, payload) {
      const axios = context.state.axios
      axios.post(
        '/api/v2/projects',
        payload
      ).then((response) => {
        console.log(response.data)
      })
    },
  }

有效载荷是VALID json!

会发生什么?好吧,POST发生了,但是,出于某种原因,我的所有参数应该是漂亮的并通过JSON发送,最终作为查询参数,重定向页面。

由于请求已经出来,它可以工作,但这不是我想要的。

我正在使用vue,vue-router和vuex。

巨大的编辑

实际上,案例是我使用语义ui。

如果您检查:https://semantic-ui.com/behaviors/form.html#/usage,您将看到任何带有submit类的DOM元素都将绑定到表单提交事件。

我删除了这个课程'提交'从按钮开始,因为我不需要它而且它有效。

所以,之前我有按钮的这个模板:

<template>
<form class="ui form" :id="formName">
  <slot name='form'></slot>
  <slot name='actions'>
    <div class="ui primary submit button" @click="post">{{submitText}}</div>
    <div class="ui secondary button" @click="reset">{{resetText}}</div>
    <div class="ui basic button" @click="back">{{backText}}</div>
  </slot>
</form>
</template>

注意第一个按钮的类。我删除了它:

<template>
<form class="ui form" :id="formName">
  <slot name='form'></slot>
  <slot name='actions'>
    <div class="ui primary button" @click="post">{{submitText}}</div>
    <div class="ui secondary button" @click="reset">{{resetText}}</div>
    <div class="ui basic button" @click="back">{{backText}}</div>
  </slot>
</form>
</template>

它现在按预期工作。但是,不确定为什么@submit.prevet="post" 有效。

0 个答案:

没有答案
相关问题