Front end error Cannot read property 'push' of undefined

1. Data area declaration variable

        ruleForm: {
            role:"",
            sdemands:"",
            demands: []
        },

2. Get the data returned by the server (the server returns role,sdemands, without demands data), assign this.ruleForm=. (this is no problem)
specific requirements are as follows:
sdemands data form as follows:: a (1), b (2)
the demands variable that wants to parse sdemands and assign it to demands, is in the form of

demands:[
    {value1:a,value2:1},
    {value1:b,value2:2}
]

3. The operation is as follows, but an error of 506 Uncaught TypeError: Cannot read property "push" of undefined is reported in the previous paragraph

                    var ded=this.ruleForm.sdemands.split(",");
                    var ded1="";
                    var ded2="";
                    for(var i=0;i<ded.length;iPP){
                        ded1=ded[i].split("(")[0];
                        ded2=ded[i].split("(")[1];
                        ded2=ded2.substring(0,ded2.length-1);
                        this.ruleForm.demands.push({value1: ded1, value2: ded2, key: Date.now()});
                    }
                    
                    

add: just declare that the array test, is assigned to test, and then test copies it to demands, but is there a better solution

                    var test=[];
                    var ded=this.ruleForm.sdemands.split(",");
                    var ded1="";
                    var ded2="";
                    for(var i=0;i<ded.length;iPP){
                        ded1=ded[i].split("(")[0];
                        ded2=ded[i].split("(")[1];
                        ded2=ded2.substring(0,ded2.length-1);
                        test.push({value1: ded1, value2: ded2, key: Date.now()});
                    }
                    console.log(test);
                    this.ruleForm.demands=test;
                    console.log(this.ruleForm.demands);
Mar.03,2021

2.(role,sdemandsdemands),this.ruleForm=...

it is estimated that you lost demands in the assignment operation in step 2.
change it to:
this.ruleForm.role=.;
this.ruleForm.sdemands=.;

Menu