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>

本文作者:Sherwin

本文链接:https://www.cnblogs.com/sherwin1995/p/16855029.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Sherwin_szw  阅读(107)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.