Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

vue请问这个报错是为什么,数据都已经渲染出来了

image.png


<div class="p-s-i l" v-for="item in product.productItems">
    <img class="icon" src="../images/home_icon_zt.png">
    <img src="../images/product_bg_cam.png">
    <p>{{item.title}}</p>
    <span>{{item.description}}</span>
</div>

var product = new Vue({
    el: '#app-product',
    data: {
        product: null,
    },
    methods: {
        imgFormatter(val) {
            return IMGPATH + val
        },
        getProductData() {
            let this_ = this
            $.ajax({
                success: function success(res) {
                    console.log(res);//已打印,结构和上图一样
                    this_.product = res.data
                }
            });
        }
})

一直报错
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

因为data中的product初始为null,null.productItems 肯定会报错的

data: {
        product: null,
    },

改为

data: {
        product: {},
    },

即可


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...