vue.js 报错无限循环

setNowMaterialType方法被无限调用,实际数组有138个元素,139开始重复打印,v-for完成后应该终止了啊?

clipboard.png

<template>
    <div class="cpepTemplate">
        <table class="tg">
            <thead>
            <tr>
                <th class="tg-baqh" colspan="4">任务项目</th>
                <th class="tg-baqh" colspan="3">材料</th>
                <th class="tg-baqh" colspan="7">实施方法</th>
                <th class="tg-baqh" colspan="3">领域</th>
                <th class="tg-baqh" colspan="7">评分</th>
            </tr>
            </thead>
            <template v-for="ele in submitData">
                    <tr v-if="!setNowMaterialType(ele)">
                        <td class="tg-yw4l leftAlign bondText" colspan="24">{{ele.MaterialType}}</td>
                    </tr>
                    <tr>
                        <td class="tg-yw4l" colspan="4">{{ele.Name}}</td>
                        <td class="tg-yw4l" colspan="3">{{ ele.Material}}</td>
                        <td class="tg-yw4l" colspan="7">{{ ele.Description}}</td>
                        <td class="tg-yw4l" colspan="3">{{ ele.Domain}}</td>
                        <td class="tg-yw4l" colspan="7">
                            <p v-for="item in ele.Options" class="optionBox">
                                <input type="radio" :value="item.Option"
                                       :id="item.ID" class="radioclass"
                                       @change="selectOption(item.QuestionID,item.Option)"
                                >
                                <label :for="item.ID" class="simbleBox"></label>
                                <label :for="item.ID" class="clickLabel">
                                    <span>{{item.Option}}:&nbsp;&nbsp;{{item.Description}}</span>
                                </label>
                            </p>
                        </td>
                    </tr>
            </template>
        </table>
        <el-button style="position: fixed;top: 675px;left: 1170px" @click.native="submitResultContent">提交测试</el-button>
    </div>
</template>
            setNowMaterialType(param) {
//                if(this.numberIndex >139 && this.numberIndex<=200 ){
//                    console.log(param)
//                }
//                this.numberIndex++;
                console.log('JJJJJJJJJJJJJJ')
                if (param.MaterialType === this.frstMaterialType) {
                    return true
                } else {
                    this.frstMaterialType = param.MaterialType;
                    return false;
                }
            },
阅读 3.1k
2 个回答

如果只是一个v-if,从你的setNowMaterialType 函数来看,并看不到循环console的情况,你可以看下submitData的值是不是有限的

先不调用setNowMaterialTypev-for循环你看是否也会报错误?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题