Skip to content

声明组件可接受的属性 ​

本节目标:理解“声明组件可接受的属性”的核心思路,并能把它用于实际开发或面试表达。 一、数组形式:

props: ['title', 'likes', 'isPublished', 'commentIds', 'author']

二、对象形式:对象的属性名和属性值分别是 prop 各自的名称和类型:

props: {  title: String,  likes: Number,  isPublished: Boolean,  commentIds: Array,  author: Object,  callback: Function,  contactsPromise: Promise // or any other constructor}

对象形式为组件提供了文档,还会在它们遇到错误的类型时从浏览器的 JavaScript 控制台提示用户。

本站总访问 — 次