If you add if to the vue function, you will report an error, but if you don't add it, it will be normal.

normal code (no if):

//
issue:function(){
    this.result = [];
    for(var i=0;i<this.formData.length;iPP){
        let obj = {
            questionUid:this.formData[i].questionUid, //id
            questionType:this.formData[i].questionType, //1:23
            //
            userBlanksDetail:{
                answer:this.formData[i].fill
            },
            //
            userOptionDetail:{
                optionUid:this.formData[i].single?this.formData[i].single:this.formData[i].mul.join(",")
            }
        }
        this.result.push(obj);
    }
    this.submit(); //
},

if you add if, you will report an error:

//
issue:function(){
    this.result = [];
    for(var i=0;i<this.formData.length;iPP){
        let obj = {
            questionUid:this.formData[i].questionUid, //id
            questionType:this.formData[i].questionType, //1:23
            //if
            if(this.formData[i].questionType == 3){
                userBlanksDetail:{
                    answer:this.formData[i].fill
                },
            }
            //
            userOptionDetail:{
                optionUid:this.formData[i].single?this.formData[i].single:this.formData[i].mul.join(",")
            }
        }
        this.result.push(obj);
    }
    this.submit(); //
},

clipboard.png

what kind of strange phenomenon is this?


if(this.formData[i].questionType == 3){
    userBlanksDetail:{
        answer:this.formData[i].fill
    },
}
Change

to

userBlanksDetail:{
    answer:this.formData[i].questionType == 3?this.formData[i].fill:''
},


for(var i=0;i<this.formData.length;iPP){
        let obj ={};
        if(this.formData[i].questionType == 3){
         obj = {
            questionUid:this.formData[i].questionUid, //id
            questionType:this.formData[i].questionType, //1:23
            //
            userBlanksDetail:{
                answer:this.formData[i].fill
            },
            //
            userOptionDetail:{
                optionUid:this.formData[i].single?this.formData[i].single:this.formData[i].mul.join(',')
            }
        }
        }else{
            obj = {
            questionUid:this.formData[i].questionUid, //id
            questionType:this.formData[i].questionType, //1:23
            //
            userOptionDetail:{
                optionUid:this.formData[i].single?this.formData[i].single:this.formData[i].mul.join(',')
            }
        }
        }
        this.result.push(obj);
    }

what kind of strange phenomenon is this?

what is your strange way of writing? I'm afraid I can't understand

.

this is a creative way of writing. Did you invent it? But javascript engine doesn't recognize it?


what kind of strange phenomenon is this?

with all due respect, this method of writing, not to mention putting it in vue, will not succeed in any js running program of react ng jquery!

if no one writes this, there is a problem with grammar. So:

let obj = {
    1: 'value1',
    2: 'value2',
    : condition ? 'value1' : 'value2',
}

// 
if () {
    obj[''] = ''
}
Menu