首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Vuejs this。$ delete会导致嵌套数组的未定义错误?

Vuejs this。$ delete会导致嵌套数组的未定义错误?
EN

Stack Overflow用户
提问于 2018-06-25 06:45:39
回答 1查看 0关注 0票数 0

版本视图(2.5.2)

undefined当试图删除一个嵌套的对象项时,我得到一个控制台。如果我添加console.log(this.sections),它会将节数组打印到控制台,所以我认为添加sections.items会做到这一点。

代码语言:javascript
复制
...
<li class="m-nav__item" @click="deleteItem(index)">
  <span href="" class="m-nav__link">
    <i class="m-nav__link-icon flaticon-delete-1"></i>
    <span class="m-nav__link-text">
      Delete
    </span>
  </span>
</li>
...

脚本

代码语言:javascript
复制
<script>

    new Vue({
        el: "#main",
        data: {
            sectionName: '',
            sectionDescription: '',
            itemName: '',
            itemPrice: '',
            itemDescription: '',
            selectedSection: null,
            sections: [
                {
                    name: "Salad",
                    description: 'Add chicken to any salad for $3.00',
                    items: [

                        {
                            name: 'Antipasto',
                            description: 'Mixed greens, Italian meats, cheeses, giardiniera pickled veggies, tomatoes, roasted peppers, onions with house Italian vinaigrette',
                            price: '$13.00'
                        }
                    ]
                },
                {
                    name: "Sandwiches",
                    description: 'Add cheese to any salad for $3.00',
                    items: [

                        {
                            name: 'Sandwich 1',
                            description: 'Mixed greens, Italian meats, cheeses, giardiniera pickled veggies, tomatoes, roasted peppers, onions with house Italian vinaigrette',
                            price: '$13.00'
                        }
                    ]
                },
                {
                    name: "Pizzas",
                    description: 'Add Pepperonis to any salad for $3.00',
                    items: [

                        {
                            name: 'Pizza 1',
                            description: 'Mixed greens, Italian meats, cheeses, giardiniera pickled veggies, tomatoes, roasted peppers, onions with house Italian vinaigrette',
                            price: '$13.00'
                        }
                    ]
                }
            ]
        },
        methods: {
            deleteSection: function (index) {
                this.sections.splice(index, 1);
            },
            addNewSection() {
                this.sections.push(
                    {
                        name: this.sections.name,
                        description: this.sections.description,
                        items: []
                    }
                );
                this.sections.name = "";
                this.sections.description = "";
            },
            addNewItem() {
                const section = this.sections.find(s => s.name === this.selectedSection);
                section.items.push({
                    name: this.itemName,
                    price: this.itemPrice,
                    description: this.itemDescription
                });
                this.itemName = "";
                this.itemPrice = "";
                this.itemDescription = ""
            },
            deleteItem: function (index) {
                console.log(this.sections.items);
                this.$delete(this.sections.items, index)
            },
        }
    });
    Vue.config.devtools = true;

</script>
EN

Stack Overflow用户

发布于 2018-06-25 16:35:14

删除是我不经常使用的东西,不在我的工具箱的顶部,特别是对于数组。

this.sections.items.splice(index,1);

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档