vue中数组有一个元素,但报"Cannot read property '0' of undefined"

责编:menVScode 2018-09-25 17:22 阅读(297)

原始代码

<table>
    <tr>
        <td>{{data.balanceGoodsList[0].goodsName}}</td>
        <td>{{data.balanceGoodsList[0].goodsPriceName}}</td>
        <td>¥{{data.balanceGoodsList[0].saleAmount}}</td>
        <td>{{data.balanceGoodsList[0].count}}</td>
        <td>¥{{data.allAcuFee}} <br>(含快递: {{data.addExpressFee}})</td>
    </tr>
</table>

报错截图:


正确写法

<table>
    <tr v-if="data.balanceGoodsList">
        <td>{{data.balanceGoodsList[0].goodsName}}</td>
        <td>{{data.balanceGoodsList[0].goodsPriceName}}</td>
        <td>¥{{data.balanceGoodsList[0].saleAmount}}</td>
        <td>{{data.balanceGoodsList[0].count}}</td>
        <td>¥{{data.allAcuFee}} <br>(含快递: {{data.addExpressFee}})</td>
    </tr>
</table>
标签: vue
前端交流群: MVC前端网(menvscode.com)-qq交流群:551903636

邮箱快速注册

忘记密码