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

質問編集履歴

3

コードの修正およびエラーメッセージの修正

2020/10/30 01:22

投稿

takochan1192
takochan1192

スコア100

title CHANGED
File without changes
body CHANGED
@@ -63,7 +63,7 @@
63
63
  <tbody>
64
64
  <template v-for="item in items">
65
65
  <tr v-for="(subitem, iSub) in item.sub" :key="subitem.id">
66
- <td v-if="iSub === 0" :rowspan="rowspanCalc(item.sub)">
66
+ <td v-if="iSub === 0" :rowspan="rowSpanCalc(item)">
67
67
  {{ item.name }}
68
68
  </td>
69
69
  <template v-if="(sub_subitem, iSub_sub) in subitem.sub_sub">
@@ -108,9 +108,13 @@
108
108
  }
109
109
  </style>
110
110
  ```
111
- しかし、このコード実行と、ブラウザ上
112
- " Property or method "rowspanCalc" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property."
113
- と表示されます。
111
+ 動的に変数はできたのですが画面の表示が下記のようになり、想定したのものと違う状況す。
112
+ ![アウトプット](622eec8af823a2d3b2f20feb59451d08.png)
114
113
 
114
+
115
+ 現状エラーとして下記のようにコンソール上に出ております。
116
+
117
+ "Property or method "iSub_sub" is not defined on the instance but referenced during render."
118
+
115
119
  解決が出来ず非常に困っております。
116
120
  どなたかお力添えをいただけませんでしょうか?

2

エラー部分の修正

2020/10/30 01:22

投稿

takochan1192
takochan1192

スコア100

title CHANGED
File without changes
body CHANGED
@@ -108,7 +108,9 @@
108
108
  }
109
109
  </style>
110
110
  ```
111
- しかし、このコードを実行すると、ブラウザ上では"Module build failed (from ./node_modules/sass-loader/dist/cjs.js):Error"と表示されます。
111
+ しかし、このコードを実行すると、ブラウザ上では
112
+ " Property or method "rowspanCalc" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property."
113
+ と表示されます。
112
114
 
113
115
  解決が出来ず非常に困っております。
114
116
  どなたかお力添えをいただけませんでしょうか?

1

コードの修正。

2020/10/30 00:04

投稿

takochan1192
takochan1192

スコア100

title CHANGED
File without changes
body CHANGED
@@ -62,22 +62,17 @@
62
62
  </thead>
63
63
  <tbody>
64
64
  <template v-for="item in items">
65
- <tr :key="item.id">
65
+ <tr v-for="(subitem, iSub) in item.sub" :key="subitem.id">
66
+ <td v-if="iSub === 0" :rowspan="rowspanCalc(item.sub)">
67
+ {{ item.name }}
68
+ </td>
69
+ <template v-if="(sub_subitem, iSub_sub) in subitem.sub_sub">
70
+ <td v-if="iSub_sub === 0" :rowspan="subitem.sub_sub.length">
71
+ {{ subitem.name }}
72
+ </td>
66
- <td :rowspan="rowspanCalc">{{ item.name }}</td>
73
+ <td :key="sub_subitem.id">{{ sub_subitem.name }}</td>
67
- <td :rowspan="item.sub.sub_sub.length">{{item.sub[0].name}}</td>
68
- <td>{{item.sub[0].sub_sub[0].name}}</td>
74
+ </template>
69
75
  </tr>
70
- <template v-for="(sub,i) in item.sub">
71
- <tr :key="sub.id" v-if="i !=0">
72
- <td>{{ sub.name }}</td>
73
- <td>{{ sub.sub_sub.name }}</td>
74
- </tr>
75
- <template v-for="(sub_sub,i) in sub.sub_sub">
76
- <tr :key="sub_sub.id" v-if="i !=0">
77
- <td>{{ sub_sub.name}}</td>
78
- </tr>
79
- </template>
80
- </template>
81
76
  </template>
82
77
  </tbody>
83
78
  </v-simple-table>
@@ -95,13 +90,12 @@
95
90
  this.items = dummyData
96
91
  }
97
92
 
98
- rowSpanCalc(){
93
+ rowSpanCalc(item: any) {
99
- this.items.forEach((el: any) => {
100
- const count = el.sub.reduce(
94
+ const count = item.sub.reduce(
101
- (total: any, curr: any) => total + curr.sub_sub.length,0)
95
+ (total: any, curr: any) => total + curr.sub_sub.length,
102
- console.log(count)
103
- return
96
+ 0
104
- })
97
+ )
98
+ return count;
105
99
  }
106
100
  }
107
101
  </script>
@@ -114,12 +108,7 @@
114
108
  }
115
109
  </style>
116
110
  ```
117
- しかし、このコードを実行すると、ブラウザ上では”An Error Occurred”と表示され
111
+ しかし、このコードを実行すると、ブラウザ上では"Module build failed (from ./node_modules/sass-loader/dist/cjs.js):Error"と表示されます。
118
- コンソール上では下記のようなエラーメッセージがでております。
119
112
 
120
- ```error
121
- Cannot read property 'length' of undefined
122
- ```
123
-
124
113
  解決が出来ず非常に困っております。
125
114
  どなたかお力添えをいただけませんでしょうか?