search

Home  >  Q&A  >  body text

javascript - prop verification in vue2, what is the use of setting default?

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

某草草某草草2778 days ago796

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你2017-05-19 10:43:31

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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:43:31

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

    reply
    0
  • 怪我咯

    怪我咯2017-05-19 10:43:31

    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

    reply
    0
  • Cancelreply