Answer the question
In order to leave comments, you need to log in
How to fix "cannot read property of undefined" error?
Actually such a question
There is a JSON file
{"tableForm": {
"head": {
"tr": [
{
"th": [
{
"id": 0,
"name": "Опции"
},
{
"id": 1,
"name": "Опции1"
},
{
"id": 2,
"name": "Опции2"
},
{
"id": 3,
"name": "Опции3"
}
]
}
]
},
"body": {
"tr": [
{
"td": [
{
"id": 0,
"label": "Какой-то текст",
"tooltip": "Тут должно быть описание",
"name": "text1",
"type": "select",
"value": "",
"select": {
"value": "",
"fields": [
{
"id": 0,
"label": "Нет",
"value": "Нет"
},
{
"id": 1,
"label": "Да",
"value": "Да"
}
]
}
},
{
"check": true
},
{
"check": true
},
{
"check": false
}
]
},
{
"td": [
{
"id": 1,
"label": "Какой-то текст",
"name": "text2",
"type": "select",
"value": "",
"tooltip": "Тут должно быть описание 2",
"select": {
"value": "",
"fields": [
{
"id": 2,
"label": "Нет",
"value": "Нет"
},
{
"id": 3,
"label": "Да",
"value": "Да"
}
]
}
},
{
"check": false
},
{
"check": true
},
{
"check": true
}
]
},
{
"td": [
{
"id": 2,
"label": "Какой-то текст",
"tooltip": "Тут должно быть описание 3",
"name": "text3",
"type": "select",
"value": "",
"select": {
"value": "",
"fields": [
{
"id": 4,
"label": "Нет",
"value": "Нет"
},
{
"id": 5,
"label": "Да",
"value": "Да"
}
]
}
},
{
"check": true
},
{
"check": false
},
{
"check": true
}
]
}
]
}
}}
<template>
<div>
<table>
<thead>
<tr v-for="(item, index) in options.head.tr" :key="index">
<th v-for="(item2, index) in item.th" :key="index">
{{ item2.name }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in options.body.tr" :key="index">
<td v-for="(item2, index) in item.td" :key="index">
<el-tooltip class="item" effect="dark" :content="item2.tooltip" placement="right-start">
<span>{{ item2.label }}</span><br/>
</el-tooltip>
<span class="el-icon-check" v-if="item2.check"></span>
{{item.value}}
<el-select v-if="item2.type == 'select'" :value="item2.value" placeholder="Выберите значение" @change="onInput(item2.name, $event)">
<el-option
v-for="item in item2.select.fields"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
import dropdown from './ui-select.vue';
export default {
props: ['options', 'vmodel'],
components: {
dropdown
},
data() {
return {
value4: ''
}
},
methods: {
onInput(field, value) {
this.$store.commit('UPDATE_TABLE_VALUE', { field, value })
}
}
}
</script>
<ui_table :options="getTableFields"></ui_table>
getTableFields() {
return this.$store.getters.getTableFields
},
getTableFields: state => {
return state.FIELDS.tableFields
},
"TypeError: Cannot read property 'tr' of undefined"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question