<!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>
原文地址:https://www.cnblogs.com/Harold-Hua/p/11749896.html
时间: 2024-11-05 22:42:33