Front vue-resource request interface
addCustomer(e){ if (!this.customer.name || !this.customer.phone || !this.customer.email) { // console.log('请添加对应信息'); this.alert = '请添加对应信息'; }else{ this.$http.post('http://localhost/phpcrud/app.php?action=create',{ "username":this.customer.name, "phone":this.customer.phone, "email":this.customer.email }).then(function(Data) { // the console.log (Data); the this $ router.push ({. path: "/" , Query: { Alert: "Add User success" } }); e.preventDefault (); }) } e.preventDefault (); }
Php obtain background data
if ($action == "create") { $input = file_get_contents("php://input"); $json = json_decode($input); $username = $json->username; $email = $json->email; $phone = $json->phone; $conn->query("set names utf8"); $result = $conn->query("insert into `users` (`username`,`email`,`phone`) values('$username','$email','Phone $ ') " ); IF ( $ Result ) { $ RES [" Message "] =" Insert success " ; } the else { $ RES [" Message "] =" insert failed " ; } }