一、Props特性 1、父组件传递、子组件要接,而且可以在组件里用父组件的数据 2、不会显示在dom的元素标签中 二、 非Props特性 1、父组件传递、子组件不接、而且没有办法使用 2、属性会展示在子组件dom标签的属性里面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>组件参数校验与非Props特性</title>
<script src="../vue.js"></script>
</head>
<body>
<div id="app">
<child content="hello"></child>
</div>
<script>
Vue.component('child', {
props: {
/*content: [Number, String]*/
content: {
type: String,
/*required: true,
default: "default value"*/
validator : function (value) {
return (value.length > 5);
}
}
},
template: "<div>{{content}}</div>"
});
var vm = new Vue({
el: '#app',
});
</script>
</body>
</html>