vue---Prop使用

一. 简述

prop使用场景:父组件需要向子组件传递消息的时候,子组件就可以定义prop属性,来接受父组件传递消息。

二. 使用方法

定义1: 带校验方式指定属性,方便其他人知道传什么类型的值

Vue.component('my-test',{
    props: {
        course: {
            type: Object,
            default() {
                return {}
            }
        },
        id: {
            type: String,
            required:true,
            default() {
                return null
            }
        }
    },
})
 

定义2: 数组形式传递


Vue.component('my-test',{
    props:['course','id']
})
 
 

使用方式:

<course-form
      :id="isOpen"
      ref="courseRef"
      :course="course">
</course-form>

猜你喜欢

转载自blog.csdn.net/qq_35321405/article/details/81634042
今日推荐