質問編集履歴
2
エラー内容の修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
firebase real databaseから読み込んだもの
|
1
|
+
firebase real databaseから読み込んだものを編集したい
|
body
CHANGED
@@ -30,11 +30,8 @@
|
|
30
30
|
mountedのなかでこのlistsの中身を取得したり,変更したりしたいと思っています.
|
31
31
|
|
32
32
|
### 発生している問題・エラーメッセージ
|
33
|
+
console.logの中身が空白で表示される.
|
33
34
|
|
34
|
-
```
|
35
|
-
エラーメッセージ
|
36
|
-
```
|
37
|
-
|
38
35
|
### 該当のソースコード
|
39
36
|
|
40
37
|
```html
|
1
コードや補足情報の追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
firebase
|
1
|
+
firebase real databaseから読み込んだものに対して変更を加える(mounted内で)
|
body
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
methods: {
|
20
20
|
change_data: function () {
|
21
21
|
for (var key in this.lists) {
|
22
|
+
以下でlistsの中にあるデータに変更や他の関数に受け渡しなどをしたい
|
22
23
|
var item = this.lists[key];
|
23
24
|
this.temp = item;
|
24
25
|
console.log(item);
|
@@ -37,13 +38,105 @@
|
|
37
38
|
### 該当のソースコード
|
38
39
|
|
39
40
|
```html
|
41
|
+
<!DOCTYPE html>
|
42
|
+
<html lang="ja">
|
43
|
+
<head>
|
44
|
+
<meta charset="UTF-8">
|
45
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
46
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
47
|
+
<!-- Semantic UI を読み込む -->
|
48
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui-css@2.4.1/semantic.min.css">
|
49
|
+
<!-- The core Firebase JS SDK is always required and must be listed first -->
|
50
|
+
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-app.js"></script>
|
51
|
+
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-auth.js"></script>
|
52
|
+
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-database.js"></script>
|
53
|
+
<title>Document</title>
|
54
|
+
</head>
|
55
|
+
<body>
|
56
|
+
<div class="ui main continer">
|
57
|
+
<div id="app">
|
58
|
+
<table class="ui celled table">
|
59
|
+
<thead>
|
60
|
+
<tr>
|
61
|
+
<th>題名</th>
|
62
|
+
<th>lat</th>
|
63
|
+
<th>lng</th>
|
64
|
+
<th>削除</th>
|
65
|
+
</tr>
|
66
|
+
</thead>
|
67
|
+
<tbody>
|
68
|
+
<tr v-for="(item,key) in lists">
|
69
|
+
<td>{{item.name}}</td>
|
70
|
+
<td>{{item.lat}}</td>
|
71
|
+
<td>{{item.lng}}</td>
|
72
|
+
<td>
|
73
|
+
<button class="ui button" v-on:click="remove_data(key)">削除</button>
|
74
|
+
</td>
|
75
|
+
</tr>
|
76
|
+
</tbody>
|
77
|
+
</table>
|
78
|
+
<div class="ui input">
|
79
|
+
<input type="text" placeholder="題名" v-model="name">
|
80
|
+
<input type="text" placeholder="コメント" v-model="comment">
|
81
|
+
</div>
|
82
|
+
<button class="ui button" v-on:click="add_data(name,comment)">追加</button>
|
83
|
+
ここにtempが入る[{{temp}}]
|
84
|
+
</div>
|
85
|
+
</div>
|
86
|
+
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
87
|
+
<script src="./config.js"></script>
|
88
|
+
<script src="./main.js"></script>
|
89
|
+
</body>
|
90
|
+
</html>
|
91
|
+
```
|
40
92
|
|
93
|
+
```javascript
|
94
|
+
new Vue({
|
95
|
+
el: "#app",
|
96
|
+
data: {
|
97
|
+
lists: [],
|
98
|
+
name: null,
|
99
|
+
comment: null,
|
100
|
+
temp:null
|
101
|
+
},
|
102
|
+
created() {
|
103
|
+
firebase.initializeApp(firebaseConfig);
|
104
|
+
var vue = this;
|
105
|
+
firebase.database().ref('/').on('value', function (snapshot) {
|
106
|
+
vue.lists = snapshot.val();
|
107
|
+
});
|
108
|
+
},
|
109
|
+
mounted() {
|
110
|
+
this.change_data();
|
111
|
+
},
|
112
|
+
methods: {
|
113
|
+
add_data: function(name,comment){
|
114
|
+
firebase.database().ref('/').push({
|
115
|
+
name: name,
|
116
|
+
comment:comment
|
117
|
+
});
|
118
|
+
this.name = '';
|
119
|
+
this.comment = '';
|
120
|
+
},
|
121
|
+
remove_data: function (key) {
|
122
|
+
firebase.database().ref('/').child(key).remove();
|
123
|
+
},
|
124
|
+
change_data: function () {
|
125
|
+
for (var key in this.lists) {
|
126
|
+
var item = this.lists[key];
|
127
|
+
this.temp = item;
|
128
|
+
console.log(item);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
},
|
132
|
+
})
|
41
133
|
```
|
42
134
|
|
43
135
|
### 試したこと
|
44
136
|
|
45
|
-
|
137
|
+
createdやmountedのなかで,console.logを使い変数の中身を確認した
|
46
138
|
|
47
139
|
### 補足情報(FW/ツールのバージョンなど)
|
48
|
-
|
49
|
-
|
140
|
+
semantic ui 2.4.1
|
141
|
+
Vue.js 最新(2.6.11)
|
142
|
+
firebase 7.6.1
|