vueフォームのデータは交互にプレゼンテーションを提出します。
5571 ワード
vue-formフォームに来てプレゼンテーションを提出してください。より良いアドバイスがあります。
1.クライアントhtml
1.クライアントhtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- , -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- , -->
<!--<script src="https://cdn.jsdelivr.net/npm/vue"></script>-->
<!-- axios -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
<h1> vue-form , , !</h1>
<table class="table">
<thead>
<tr>
<th>box</th>
<th>new</th>
<th>rank</th>
<th>desc</th>
<th>title</th>
</tr>
</thead>
<tbody>
<tr v-for="(v,i) in tabData">
<td>{{v.box}}</td>
<td>{{v.new}}</td>
<td>{{v.rank}}</td>
<td><input type="text" v-model="tabData[i]['desc']"></td>
<td>{{v.title}}</td>
</tr>
</tbody>
</table>
<p>
<button @click="submit" type="primary"> </button>
</p>
</div>
<script type="application/javascript">
var app = new Vue({
el: '#app',
data: {
tabData: [
{
"box": 21650000,
"new": true,
"rank": 1,
"desc": 'desc1',
"title": "Geostorm"
},
{
"box": 13300000,
"new": true,
"rank": 2,
"desc": 'desc2',
"title": "Happy Death Day"
}
],
form: {
firstName: 'Fred',
lastName: 'Flintstone'
}
},
methods: {
submit: function () {
/**
* axios form
**/
function jsonData(arr) {
let json = "";
function fors(data, attr=false) {
data = JSON.parse(JSON.stringify(data));
for (let key in data) {
if(Array.isArray(data[key]) || Object.prototype.toString.apply(data[key]) ==='[object Object]'){
fors(data[key], true);
} else {
if(attr){
json = json + '&'+ key + '[]' +'=' + data[key];
}else {
json = json + '&'+ key +'=' + data[key];
}
}
}
}
fors(arr);
return json;
}
console.log(jsonData(this.form));
console.log('---------------');
console.log(jsonData(this.tabData));
console.log('---------------');
//
axios({
url: './index.php',
method: 'post',
data: jsonData(this.tabData),
/**
* 1. application/json :
* * transformRequest
* * jsonData
* 2. PHP application/json
* * $form = file_get_contents('php://input');
* * $form = json_decode($form);
*
* 3. :** ** application/json 。
* 4. JQ
*/
transformRequest: [function (data) {
// Do whatever you want to transform the data
if(Array.isArray(data) || Object.prototype.toString.apply(data) ==='[object Object]'){
let ret = '';
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
} else {
return data;
}
}],
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function (res) {
console.log(' ');
console.log(res.data);
})
}
}
});
</script>
<style type="text/css">
table{border-collapse: collapse;border: 1px solid red;}
th,td{border: 1px solid red;}
</style>
</body>
</html>
2.業務端、PHPを例に
<?php
header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Headers:x-requested-with,content-type');
/**
* x-www-form-urlencoded form
*/
echo json_encode($_REQUEST);
/**
* 1. $GLOBALS ["HTTP_RAW_POST_DATA"];
* 2. file_get_contents('php://input');
*
* application/json
*/
$form = file_get_contents('php://input');
$form = json_decode($form);
print_r($form);
以上のこのvueフォームのデータがインタラクティブにプレゼンテーション教程を提出しました。つまり、小編集が皆さんに提供した内容は全部分かりました。参考にしてもらいたいです。どうぞよろしくお願いします。