javascript - prop verification in vue2, what is the use of setting default?
某草草
某草草 2017-05-19 10:41:31
0
3
792

html code:

<prop-ver :prop-a="num" :prop-b="num2"></prop-ver>

js code:

var propVer={
    prop:{
        propA:{
            type:Number,
            default:100
        },
        propB:{
            type:Number,
            default:100
        }
    },
    tempalte:'<p>{{propA}}------{{propB}}</p>'
};
new Vue({
    el:'#el',
    data:{
        num:'222',
        num2:222
    },
    components:{
        'prop-ver':propVer
    }
});

The code is as above. "I feel that default is useless and has no prompts or effects.
Solved: I originally thought that the value passed in did not meet the type requirements, and then the default value was used. It turns out to be the default value when there is no value

某草草
某草草

reply all(3)
世界只因有你

Make sure it won’t be undefined when you need to use it

我想大声告诉你

The default value, because you passed num and num2 to the two props, the default value is overwritten

刘奇

Resolved: I thought default was the value passed in if it did not meet the type requirements, and then it was the default value. It turns out to be the default value when there is no value

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template