首页 > 其他 > 详细

Vue实战笔记

时间:2019-03-28 23:11:08      阅读:139      评论:0      收藏:0      [点我收藏+]

1、组件的属性

技术分享图片

例子:

<template>
  <div class="hello">
    <test-props
      name="demo"
      title="我是title"
      :names="names"
      ></test-props>
  </div>
</template>

<script>
  import TestProps from components/TestProps

  export default {
    name: HelloWorld,
    data () {
      return {
        names: 我是Name
      }
    },
    components: {
      TestProps
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus" rel="stylesheet/stylus" scoped>
</style>
<template>
  <div class="testProps">
    {{names}}
  </div>
</template>

<script>
  export default {
    name: TestProps,
    // inheritAttrs: false, // 用来控制是否显示原生属性
    props: {
      names: {
        type: String,
        default: ‘‘
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>

</style>

技术分享图片

<template>
  <div class="testProps">
    {{names}}
  </div>
</template>

<script>
  export default {
    name: TestProps,
    inheritAttrs: false, // 用来控制是否显示原生属性
    props: {
      names: {
        type: String,
        default: ‘‘
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>

</style>

技术分享图片

 

 title是原生属性,当inheritAttrs为false时,原生属性不显示

Vue实战笔记

原文:https://www.cnblogs.com/zhaobao1830/p/10618412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!