Vue——组件参数校验与非Props特性
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>组件参数校验与非Props特性</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="root"> <child :content="'组件参数校验'"></child> <lastchild :text="'非Props特性'"></lastchild> </div> <script type="text/javascript"> Vue.component('child', { props: { // content: Number // content: [String,Number] content: { type: String, // required: false, // default: 'default Value', // validator(value) { // return(value.length > 5) // } } }, template: '<div>{{content}}</div>' }) Vue.component('lastchild', { template: '<div>非Props特性</div>' }) var rm = new Vue({ el: '#root' }) </script> </body> </html>
略懂,略懂....