Vuejs 的props(参数验证)

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<script src="https://unpkg.com/vue/dist/vue.js"></script>

<title>Document</title>

</head>

<body>

<div id = "myApp">

<h1>身世之谜</h1>

<show-member-info name = 'haohao' :age = "23" :detail = "{address:'earth',language:'世界语'}"></show-member-info>

</div>

<script>

Vue.component('show-member-info',{

props:{

name:{

type:String,

required:true, //require的意为必填选项

},

age:{

type:Number,

validator:function(value){

return value >= 0 && value <= 130;

}

},

detail:{

type:Object,

default:function(){

return{

address:'US',

language:'English',

};

}

},

},

template:'<div><strong>姓名:{{this.name}}</strong><br/>'

+'<strong>年龄:{{this.age}}</strong><br/>'

+'<strong>地址:{{this.detail.address}}</strong><br/>'

+'<strong>语言:{{this.detail.language}}</strong><br/></div>',

});

var myApp = new Vue({

el:"#myApp",

data:{

myscore:99,

},

});

</script>

</body>

</html>

猜你喜欢

转载自blog.csdn.net/xlh006/article/details/83650857