美文网首页
CnodeJS-Vue 遇到的问题

CnodeJS-Vue 遇到的问题

作者: YZY君 | 来源:发表于2017-08-04 10:58 被阅读41次

    <span>{{index+1}}楼•{{reply.create_at.substr(0,10)}}</span>
    另一个组件中同样使用的{{item.create_at.substr(0,10)}}没有问题,这里会报错,但是页面内容显示正常。

    vue.esm.js?65d7:479 [Vue warn]: Error in render function: "TypeError: Cannot read property 'substr' of undefined"
    
    found in
    
    ---> <ArticleComp> at /Users/yzy/CODE/CnodeJS-Vue/src/components/articleComp.vue
           <App> at /Users/yzy/CODE/CnodeJS-Vue/src/App.vue
             <Root>
    
    vue.esm.js?65d7:566 TypeError: Cannot read property 'substr' of undefined
        at Proxy.render (articleComp.vue?9c74:25)
        at VueComponent.Vue._render (vue.esm.js?65d7:4128)
        at VueComponent.updateComponent (vue.esm.js?65d7:2538)
        at Watcher.get (vue.esm.js?65d7:2881)
        at new Watcher (vue.esm.js?65d7:2870)
        at mountComponent (vue.esm.js?65d7:2542)
        at VueComponent.Vue$3.$mount (vue.esm.js?65d7:7863)
        at VueComponent.Vue$3.$mount (vue.esm.js?65d7:10066)
        at init (vue.esm.js?65d7:3501)
        at createComponent (vue.esm.js?65d7:5147)
    

    v-for 的index 使用

    v-for遍历数组时的参数顺序 变更

    当包含 index时,之前遍历数组时的参数顺序是 (index, value)。现在是 (value, index),来和 JavaScript 的原生数组方法(例如 forEach和 map)保持一致。

     <div class="cell" v-for='(reply,index) in article.replies'>
       <span>{{index+1}}楼•{{reply.create_at.substr(0,10)}}</span>
    </div>
    

    相关文章

      网友评论

          本文标题:CnodeJS-Vue 遇到的问题

          本文链接:https://www.haomeiwen.com/subject/gbrvlxtx.html