質問編集履歴

2

エラー内容の修正

2020/01/10 14:27

投稿

ayousanz
ayousanz

スコア258

test CHANGED
@@ -1 +1 @@
1
- firebase real databaseから読み込んだものに対て変更を加える(mounted内で)
1
+ firebase real databaseから読み込んだものを編集たい
test CHANGED
@@ -62,13 +62,7 @@
62
62
 
63
63
  ### 発生している問題・エラーメッセージ
64
64
 
65
-
66
-
67
- ```
68
-
69
- エラーメッセージ
65
+ console.logの中身が空白で表示される.
70
-
71
- ```
72
66
 
73
67
 
74
68
 

1

コードや補足情報の追加

2020/01/10 14:27

投稿

ayousanz
ayousanz

スコア258

test CHANGED
@@ -1 +1 @@
1
- firebase のデータベースから読み込んだものに対して変更を加える(mounted内で)
1
+ firebase real databaseから読み込んだものに対して変更を加える(mounted内で)
test CHANGED
@@ -40,6 +40,8 @@
40
40
 
41
41
  for (var key in this.lists) {
42
42
 
43
+ 以下でlistsの中にあるデータに変更や他の関数に受け渡しなどをしたい
44
+
43
45
  var item = this.lists[key];
44
46
 
45
47
  this.temp = item;
@@ -76,7 +78,189 @@
76
78
 
77
79
  ```html
78
80
 
79
-
81
+ <!DOCTYPE html>
82
+
83
+ <html lang="ja">
84
+
85
+ <head>
86
+
87
+ <meta charset="UTF-8">
88
+
89
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
90
+
91
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
92
+
93
+ <!-- Semantic UI を読み込む -->
94
+
95
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui-css@2.4.1/semantic.min.css">
96
+
97
+ <!-- The core Firebase JS SDK is always required and must be listed first -->
98
+
99
+ <script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-app.js"></script>
100
+
101
+ <script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-auth.js"></script>
102
+
103
+ <script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-database.js"></script>
104
+
105
+ <title>Document</title>
106
+
107
+ </head>
108
+
109
+ <body>
110
+
111
+ <div class="ui main continer">
112
+
113
+ <div id="app">
114
+
115
+ <table class="ui celled table">
116
+
117
+ <thead>
118
+
119
+ <tr>
120
+
121
+ <th>題名</th>
122
+
123
+ <th>lat</th>
124
+
125
+ <th>lng</th>
126
+
127
+ <th>削除</th>
128
+
129
+ </tr>
130
+
131
+ </thead>
132
+
133
+ <tbody>
134
+
135
+ <tr v-for="(item,key) in lists">
136
+
137
+ <td>{{item.name}}</td>
138
+
139
+ <td>{{item.lat}}</td>
140
+
141
+ <td>{{item.lng}}</td>
142
+
143
+ <td>
144
+
145
+ <button class="ui button" v-on:click="remove_data(key)">削除</button>
146
+
147
+ </td>
148
+
149
+ </tr>
150
+
151
+ </tbody>
152
+
153
+ </table>
154
+
155
+ <div class="ui input">
156
+
157
+ <input type="text" placeholder="題名" v-model="name">
158
+
159
+ <input type="text" placeholder="コメント" v-model="comment">
160
+
161
+ </div>
162
+
163
+ <button class="ui button" v-on:click="add_data(name,comment)">追加</button>
164
+
165
+ ここにtempが入る[{{temp}}]
166
+
167
+ </div>
168
+
169
+ </div>
170
+
171
+ <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
172
+
173
+ <script src="./config.js"></script>
174
+
175
+ <script src="./main.js"></script>
176
+
177
+ </body>
178
+
179
+ </html>
180
+
181
+ ```
182
+
183
+
184
+
185
+ ```javascript
186
+
187
+ new Vue({
188
+
189
+ el: "#app",
190
+
191
+ data: {
192
+
193
+ lists: [],
194
+
195
+ name: null,
196
+
197
+ comment: null,
198
+
199
+ temp:null
200
+
201
+ },
202
+
203
+ created() {
204
+
205
+ firebase.initializeApp(firebaseConfig);
206
+
207
+ var vue = this;
208
+
209
+ firebase.database().ref('/').on('value', function (snapshot) {
210
+
211
+ vue.lists = snapshot.val();
212
+
213
+ });
214
+
215
+ },
216
+
217
+ mounted() {
218
+
219
+ this.change_data();
220
+
221
+ },
222
+
223
+ methods: {
224
+
225
+ add_data: function(name,comment){
226
+
227
+ firebase.database().ref('/').push({
228
+
229
+ name: name,
230
+
231
+ comment:comment
232
+
233
+ });
234
+
235
+ this.name = '';
236
+
237
+ this.comment = '';
238
+
239
+ },
240
+
241
+ remove_data: function (key) {
242
+
243
+ firebase.database().ref('/').child(key).remove();
244
+
245
+ },
246
+
247
+ change_data: function () {
248
+
249
+ for (var key in this.lists) {
250
+
251
+ var item = this.lists[key];
252
+
253
+ this.temp = item;
254
+
255
+ console.log(item);
256
+
257
+ }
258
+
259
+ }
260
+
261
+ },
262
+
263
+ })
80
264
 
81
265
  ```
82
266
 
@@ -86,12 +270,14 @@
86
270
 
87
271
 
88
272
 
89
- ここに問題に対て試しことを記載してください。
273
+ createdやmountedのなかで,console.logを使い変数の中身を確認した
90
274
 
91
275
 
92
276
 
93
277
  ### 補足情報(FW/ツールのバージョンなど)
94
278
 
95
-
96
-
97
- ここにより詳細な情報を記載してください。
279
+ semantic ui 2.4.1
280
+
281
+ Vue.js 最新(2.6.11)
282
+
283
+ firebase 7.6.1