Narutocc / Vue

:smirk_cat:Vue is a progressive framework for building user interfaces. Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with modern tooling and supporting libraries.
1 stars 0 forks source link

props 验证 #46

Open Narutocc opened 6 years ago

Narutocc commented 6 years ago
<script>
  /*可以为prop定制验证方式,如下:*/
  Vue.component('my-component', {
    props: {
      // 基础的类型检查 ('null'匹配任何类型)
      propA: Number,
      // 多个可能的类型
      propB: [String, Number],
      // 必填的字符串
      propC: {
        type: String,
        required: true
      },
      // 带有默认值的数字
      propD: {
        type: Number,
        default: 100
      }
    }
  })
</script>

type 可以是下列原生构造函数中的一个:

String / Number / Boolean / Array / Object / Date / Function / Symbol