博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Vue] Props Validations
阅读量:7033 次
发布时间:2019-06-28

本文共 1039 字,大约阅读时间需要 3 分钟。

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      }    }  }})

 

转载地址:http://jiyal.baihongyu.com/

你可能感兴趣的文章
关于循环嵌套循环
查看>>
Scala中常见的容器 Option(选项)
查看>>
算法-蛇型矩阵
查看>>
路由交换IOS的备份与还原
查看>>
05.swift ?可选类型
查看>>
JavaSE 学习参考:方法的参数
查看>>
跟小博老师一起学习MyBatis ——MyBatis搭建运行环境
查看>>
linux ***
查看>>
豆瓣网站为什么会选择python而不是ruby
查看>>
在腾讯云服务器上体验Docker
查看>>
OpenStack Rabbit 集群实现
查看>>
我的友情链接
查看>>
mysql存储过程
查看>>
DDD(领域驱动设计)jpatable主键生成策略RBAC打造通用WEB权限
查看>>
我的友情链接
查看>>
混乱字符串的字段提取
查看>>
我的友情链接
查看>>
深度有趣 | 10 股票价格预测
查看>>
Java虚拟机类加载机制
查看>>
mpls的基本概念
查看>>