Answer the question
In order to leave comments, you need to log in
How to send form data to php file using vue-resource?
I have the following Vue.js code (vue-resource plugin included), what should I write in the mail.php file so that the file accepts the data entered in the form?
<template>
<div id="app">
<div class="editor">
<form @submit.prevent="savePost()">
<input type="text" placeholder="Заголовок" v-model="post.a">
<textarea placeholder="Текст" v-model="post.b"></textarea>
<button>Опубликовать</button>
</form>
</div>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
endpoint: 'mail.php',
posts: [],
post: {}
}
},
computed: {
resource() {
return this.$resource('mail.php')
}
},
methods: {
savePost() {
this.resource.save(this.post)
},
getSinglePost() {
this.resource.get().then(function(response) {
this.post = response.data
})
}
}
}
</script>
Answer the question
In order to leave comments, you need to log in
VUE-resource is no longer relevant. Even developers advise using axios.
You must send a POST request to a PHP file with JS. In a PHP file, you have to accept $_POST['value'] data and process it already.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question