xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

vue 使用 object 作为循环中的响应式的数据源 All In One

vue 使用 object 作为循环中的响应式的数据源 All In One

for 循环中的数据,响应不同步 bug

bug

直接使用 array 包裹 '', boolean ❌

            imgSetNames: [
                '',
            ],
            showInputErrors: [
                false,
            ],

solution

直接使用 array 包裹 object ✅

            imgSetNames: [
                {
                    setName: '',
                },
            ],
            showInputErrors: [
                {
                    showError: false
                },
            ],
            // imgSetNames: [
            //     '',
            // ],
            // showInputErrors: [
            //     false,
            // ],

            // vm.$set(vm.items, indexOfItem, newValue)
            // this.$set(this.imgSetNames, this.imgSetNames.length - 1, '');
            // this.$set(this.showInputErrors, this.showInputErrors.length - 1, false);
            // this.imgSetNames.push('');
            // this.showInputErrors.push(false);
            this.imgSetNames.push({
                setName: '',
            });
            this.showInputErrors.push({
                showError: false,
            });
            this.ruleForm.creativeList[this.creativeIndex].imageSetNames.push({
                image_set_name: '',
            });
            // this.creativeObj.imageSetNames.push({
            //     image_set_name: '',
            // });


            this.creativeGroupList = [obj];
            // this.imgSetNames = [''];
            // this.showInputErrors = [false];
            this.imgSetNames = [{
                setName: '',
            }];
            this.showInputErrors = [{
                showError: false,
            }];
            this.ruleForm.creativeList[this.creativeIndex].imageSetNames = [{
                image_set_name: '',
            }];
            this.ruleForm.creativeList[this.creativeIndex].imgList = [];
            this.ruleForm.creativeList[this.creativeIndex].imageLength = value;
            this.ruleForm.creativeList[this.creativeIndex].imageBoxesLength = value;


        imgSetNameChange (index) {
            console.log('组图名称 index', index);
            this.creativeObj.imageSetNames[index].image_set_name = this.imgSetNames[index].setName ?? '';
        },
        imgSetNameValidator (rule, value, callback, index) {
            const errMsg = '组图名称不可为空';
            console.log('组图名称 value', value, this.showInputErrors, index);
            if(!value) {
                this.showInputErrors[index].showError = true;
                callback(errMsg);
            } else {
                this.showInputErrors[index].showError = false;
                callback();
            }
        },


refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(388)  评论(1编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-08-18 how to using Linux pipe command output another command's help content to a file
2020-08-18 hackr.io & Programming Courses & Programming Tutorials
2020-08-18 SQL Tutorials & MySQL & SQL Server
2020-08-18 How to use PyPI to publish a Python package All In One
2020-08-18 AIoT & IoT
2020-08-18 HTML 5.3
2020-08-18 js Memory Management
点击右上角即可分享
微信分享提示