提交表单后重新加载屏幕-Vue.js

时间:2019-01-27 22:37:28

标签: vue.js vuejs2 vue-component

我正在创建Discord命令创建器应用程序。我让客户端正确地与服务器对话并输出我想要的内容。问题是,一旦我提交了表单,页面就不会刷新。下面有模板和脚本。

<template>
  <form v-on:submit="addCommand">
    <div id="container" class="col-md-5 m-auto">
      <div class="card card-body">
        <h1 class="text-center mb-3"><i class="fab fa-discord"></i> Command Creator</h1>
          <div class="form-group">
            <label for="command">Command</label>
            <input type="text" v-model="command" class="form-control" placeholder="Please enter a command." />
          </div>
          <div class="form-group">
            <label for="output">Output</label>
            <input type="text" v-model="output" class="form-control" placeholder="Please enter an output." />
          </div>
          <button type="submit" class="btn btn-primary btn-block">Create</button>
      </div>
    </div>
  </form>
</template>

<script>
export default {
  name: 'Dashboard',
  data () {
    return {
      command: '',
      output: ''
    }
  },
  methods: {
    addCommand (e) {
      this.axios.post('http://localhost:3000/server', {
        command: this.command,
        output: this.output
      })
      e.preventDefault()
    }
  }
}
</script>

0 个答案:

没有答案