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

質問編集履歴

1

追加

2019/07/23 14:44

投稿

kaori_luna
kaori_luna

スコア14

title CHANGED
File without changes
body CHANGED
@@ -38,4 +38,56 @@
38
38
  value="2">banana
39
39
  </li>
40
40
  <ul>
41
+ ```
42
+
43
+ Vue.js
44
+
45
+ ```
46
+ let app = new Vue({
47
+ el: "#app",
48
+ data: {
49
+ fruit_type:1,
50
+ fruit_type_optional:[],
51
+ errors:{}
52
+ },
53
+
54
+
55
+ created:function () {
56
+ let count_data = 0;
57
+ for (let key in old_data) {
58
+ if (old_data[key] != null && old_data[key] != "") {
59
+ count_data += 1;
60
+ }
61
+ }
62
+ if (count_data > 0) {
63
+ for (let key in old_data) {
64
+ this.$set(this, key, old_data[key]);
65
+ }
66
+ } else {
67
+ let that = this;
68
+ axios.get('api/getSession')
69
+ .then(res => {
70
+ Object.entries(res.data).map(function (data) {
71
+ console.log(data[0], data[1]);
72
+ if(data[0]!= '_token') {
73
+ that.$set(that, data[0], data[1]);
74
+ }
75
+ });
76
+ })
77
+ .catch(error => {
78
+
79
+ this.message = 'データの取得に失敗しました。';
80
+ });
81
+
82
+ }
83
+
84
+ },
85
+
86
+ }
87
+ });
88
+
89
+
90
+
91
+
92
+
41
93
  ```