質問するログイン新規登録

回答編集履歴

1

追記

2021/05/18 14:04

投稿

Tatsunosuke
Tatsunosuke

スコア599

answer CHANGED
@@ -1,3 +1,82 @@
1
+ [追記]
2
+ 以下で確認取れました!
3
+ axiosをgetに変更し、URLのパラメータで渡してますので、Laravel側ちょっと弄ってやってください。
4
+
5
+ 普段axios使わないので詳しい原因は正直不明なんですが、
6
+ なんでかpostでこのデータの渡し方だとエラーになるので、getに変更し、URLのパラメータでテストした結果問題なく値が返ってきてます。
7
+
8
+ お試しください!
9
+
10
+
11
+
12
+ ```nuxt
13
+ axios.post('http://127.0.0.1:8000/api/posts', {
14
+ name: this.name,
15
+ content: this.content,
16
+ })
17
+ ```
18
+
19
+
20
+
21
+
22
+ ```nuxt
23
+ <template lang="html">
24
+ <div class="container">
25
+ <div v-if="save" class="alert alert-primary" role="alert">
26
+ 保存しました
27
+
28
+ </div>
29
+ <form>
30
+ <div class="form-group">
31
+ <label for="TopicTitle">タイトル</label>
32
+ <input type="text" class="form-control" id="TopicTitle" v-model="name">
33
+ </div>
34
+ <div class="form-group">
35
+ <label for="TopicContent">内容</label>
36
+ <textarea class="form-control" id="TopicContent" rows="3" v-model="content"></textarea>
37
+ </div>
38
+ <button type="submit" class="btn btn-primary" @click.prevent="create">登録</button>
39
+ </form>
40
+ </div>
41
+ </div>
42
+ </template>
43
+
44
+ <script>
45
+ import axios from "axios";
46
+ export default {
47
+ data() {
48
+ return {
49
+ name: "",
50
+ content: "",
51
+ save: "",
52
+ url:""
53
+ };
54
+ },
55
+ methods: {
56
+ async create() {
57
+ await axios
58
+ .get(
59
+ url+"?name=" +
60
+ this.name +
61
+ "&content=" +
62
+ this.content
63
+ )
64
+ .then((response) => {
65
+ console.log(response);
66
+ this.name = "";
67
+ this.content = "";
68
+ this.save = true;
69
+ console.log("created");
70
+ });
71
+ },
72
+ },
73
+ };
74
+ </script>
75
+ ```
76
+
77
+
78
+ ---
79
+
1
80
  ざっとみただけなんでダメだったらごめんなさい。
2
81
 
3
82