|
报错如下
- [code]undefined:132: TypeError: Cannot read property 'head' of undefined
- TypeError: Cannot read property 'head' of undefined
- at e.module.exports.children.children.children.children.attr.src (eval at ur (unknown source), <anonymous>:132:70)
- at rc.get (<anonymous>:4:1578)
- at rc.update (<anonymous>:4:2151)
- at Ys.notify (<anonymous>:4:124)
- at Object.defineProperty.set [as list] (<anonymous>:1:20255)
- at <anonymous>:1:22177
- at e.<anonymous> (<anonymous>:1:27590)
- at rc.update (<anonymous>:4:2220)
- at Ys.notify (<anonymous>:4:124)
- at Object.defineProperty.set [as hot] (<anonymous>:1:20255)
- com.eclipsesource.v8.V8ScriptExecutionException
复制代码 代码如下:- <block for="{{(index, value) in list}}" if="{{index%3===0}}">
- <list-item type="product" class="content-item">
- <div class="item-info" if="{{list[index].head}}">
- <img src="{{list[index].head}}" alt="" class="img-head" @click="{{headClick(list[index])}}">
- <text class="text-name">{{list[index].nickname}}</text>
- </div>
- <div class="item-info" if="{{list[index+1] && list[index+1].head}}">
- <img src="{{list[index+1].head}}" alt="" class="img-head" @click="{{headClick(list[index+1])}}">
- <text class="text-name">{{list[index+1].nickname}}</text>
- </div>
- <div class="item-info" if="{{list[index+2] && list[index+2].head}}">
- <img src="{{list[index+2].head}}" alt="" class="img-head" @click="{{headClick(list[index+2])}}">
- <text class="text-name">{{list[index+2].nickname}}</text>
- </div>
- </list-item>
- </block>
复制代码 报错的原因是list[index]为undefined,但是通过if,判断list[index]存在之后才会执行,报错之后不影响页面渲染及功能使用,请问如何避免使用下一个索引引用时不报错
|
|