zoukankan      html  css  js  c++  java
  • [Vue] Props Validations

    Components can specify requirements for its props, such as the types you’ve already seen. If a requirement isn’t met, Vue will warn you in the browser’s JavaScript console. This is especially useful when developing a component that’s intended to be used by others.

    Vue.component('my-component', {
      props: {
        // Basic type check (`null` matches any type)
        propA: Number,
        // Multiple possible types
        propB: [String, Number],
        // Required string
        propC: {
          type: String,
          required: true
        },
        // Number with a default value
        propD: {
          type: Number,
          default: 100
        },
        // Object with a default value
        propE: {
          type: Object,
          // Object or array defaults must be returned from
          // a factory function
          default: function () {
            return { message: 'hello' }
          }
        },
        // Custom validator function
        propF: {
          validator: function (value) {
            // The value must match one of these strings
            return ['success', 'warning', 'danger'].indexOf(value) !== -1
          }
        }
      }
    })

    Doc

  • 相关阅读:
    lambda表达式
    Shiro身份认证---转
    反转数组
    HashMap去重
    开发工具软件下载地址
    setInterval的使用和停用
    手机端的META
    spring自定义参数绑定(日期格式转换)
    mybatis注解动态sql
    SpringMVC文件上传
  • 原文地址:https://www.cnblogs.com/Answer1215/p/9428133.html
Copyright © 2011-2022 走看看