提交表单后重新加载屏幕-Vue.js
我正在创建一个Discord command creator应用程序。我让客户机正确地与服务器对话并输出我想要的内容。问题是一旦我提交表单,页面就不会刷新。下面是我的模板和脚本提交表单后重新加载屏幕-Vue.js,vue.js,vuejs2,vue-component,Vue.js,Vuejs2,Vue Component,我正在创建一个Discord command creator应用程序。我让客户机正确地与服务器对话并输出我想要的内容。问题是一旦我提交表单,页面就不会刷新。下面是我的模板和脚本 <template> <form v-on:submit="addCommand"> <div id="container" class="col-md-5 m-auto"> <div class="card card-body">
<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>
命令创建者
命令
输出
创造
导出默认值{
名称:“仪表板”,
数据(){
返回{
命令:“”,
输出:“”
}
},
方法:{
添加命令(e){
此.axios.post('http://localhost:3000/server', {
command:this.command,
output:this.output
})
e、 预防默认值()
}
}
}
尝试删除e.preventDefault()
对于Vue应用程序,您可能不希望刷新页面;这将重新加载整个应用程序。查看页面“刷新”时,您试图实现的目标是什么?