[英]Vuejs - Retrieve input value
I have a simple input to get user's email and I want to send an http post request to save the email in the DB. 我有一个简单的输入即可获取用户的电子邮件,并且我想发送一个http发布请求以将电子邮件保存在数据库中。
This is the "form": 这是“表格”:
<input v-model="email" id="email" type="email" name="email" placeholder="Inser your email...">
<input id="submitButton" type="submit" value="Save" v-if="isValidEmail" v-on:click="save(email)">
This is the Vue script: 这是Vue脚本:
new Vue({
el: '#body',
data: {
email: ''
},
computed: {
isValidEmail: function(){
var re = /\S+@\S+\.\S+/;
return re.test(this.email);
}
},
methods: {
save: function(passedEmail){
this.$http.post('action.php', passedEmail, function (data) {
swal({
title: data.title,
text: data.text,
timer: 5000,
type: data.type,
showConfirmButton: true
});
}).error(function (data) {
swal({
title: 'Errore',
text: 'Si è verificato un errore sconosciuto.',
timer: 5000,
type: 'error',
showConfirmButton: true
});
});
}
}
});
How can I get the email value in my action.php
file? 如何在
action.php
文件中获取电子邮件值?
I tried a simple print_r($_POST)
but it is empty while passedEmail
contains the actual email. 我尝试了一个简单的
print_r($_POST)
但在passedEmail
包含实际电子邮件时为空。
You should pass an object as data, 您应该将对象作为数据传递,
this.$http.post('action.php', {email: passedEmail}, function (data) {
...
})
Finally I solved. 终于我解决了。
The problem is that Vue ( at least in my case ) send the data in the Request's playload so to retrieve the input you need to use: 问题是Vue(至少在我的情况下)在Request的播放负载中发送数据,以便检索您需要使用的输入:
$data = file_get_contents("php://input");
var_dump($data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.