控制台报这个错的话,先排查html代码中是否使用了xxx.length,代码中是这样写的,
<el-table>
<el-table-column label="操作" align="center" width="330">
<template slot-scope="scope">
<el-button v-show="scope.row.children.length>0" size="mini"
type="primary" plain @click="dowload(scope.row)">
预览</el-button>
<el-button v-show="scope.row.children.length>0" size="mini"
type="primary" plain @click="dowload(scope.row)">
下载</el-button>
<el-button v-show="scope.row.children.length == 0" size="mini"
type="primary" plain @click="addCase(scope.row)">
添加</el-button>
<el-button v-show="scope.row.children.length == 0" size="mini"
type="primary" plain @click="approDetail(scope.row.id)">
查看</el-button>
<el-button v-show="scope.row.children.length == 0"
size="mini"type="primary" plain @click="approDel(scope.row.id)">
删除</el-button>
</template>
</el-table-column>
</el-table>
这样写造成报错的原因是没有预先判断数组是否存在,需要先对数组进行非空验证:scope.row.children!= undefined,如下正确写法:
<el-table>
<el-table-column label="操作" align="center" width="330">
<template slot-scope="scope">
<el-button v-show="scope.row.children!= undefined &&
scope.row.children.length>0" size="mini" type="primary" plain
@click="dowload(scope.row)">
预览</el-button>
<el-button v-show="scope.row.children!= undefined &&
scope.row.children.length>0" size="mini" type="primary" plain
@click="dowload(scope.row)">
下载</el-button>
<el-button v-show="scope.row.children!= undefined &&
scope.row.children.length == 0" size="mini" type="primary" plain
@click="addCase(scope.row)">
添加</el-button>
<el-button v-show="scope.row.children!= undefined &&
scope.row.children.length == 0" size="mini" type="primary" plain
@click="approDetail(scope.row.id)">
查看</el-button>
<el-button v-show="scope.row.children!= undefined &&
scope.row.children.length == 0" size="mini" type="primary" plain
@click="approDel(scope.row.id)">
删除</el-button>
</template>
</el-table-column>
</el-table>