props配置项指定默认值

定义

props是组件间通信,父传子,自定义属性时,子组件间中接收父组件中传入的数据使用的配置项

<script>
import New from './components/NewComponents.vue'
export default{
  components:{
    New,
  },
  data(){
    return{
      msg:'123'
    }
  }
}
</script>

<template>
  <New msg=""></New>
</template>

子组件

<script>
    export default{
        props:{
            msg:{
                type:String, //限制类型,会报错
                required:true,//是否必传,会报错
                default:'sb' //没传显示
            }
        }
    }
</script>
<template>
<div>
    <button>{{msg}}</button>
</div>
</template>
posted @ 2022-11-03 16:47  Sherwin_szw  阅读(92)  评论(0编辑  收藏  举报