首页 > 其他分享 >030.Vue3入门,父页面给子页面传递attribute属性

030.Vue3入门,父页面给子页面传递attribute属性

时间:2024-08-11 18:16:15浏览次数:7  
标签:vue attribute Child Father 如下 Vue3 属性 页面

1、App.vue代码如下:

<template>
  <Father/>
</template>

<script setup>
import Father from './view/Father.vue'
</script>

<style>
</style>

2、Father.vue代码如下:

<template>
  <h3>父页面</h3>
  <p>父页面属性</p>
  <Child class="attr-container"/>
</template>

<script>
import Child from './Child.vue'

export default {
  components: {Child}
}
</script>

<style scoped>
</style>

3、Child.vue代码如下:

<template>
  <!--  必须只有唯一的根元素-->
  <div>
    <h3>子页面</h3>
    <p>子页面属性</p>
  </div>
</template>

<script>
export default {
  //默认是继承,如果不继承,需要设置为false
  inheritAttrs: true
}
</script>

<style scoped>
.attr-container {
  color: red;
}
</style>

4、效果如下:

 

标签:vue,attribute,Child,Father,如下,Vue3,属性,页面
From: https://www.cnblogs.com/tianpan2019/p/18353712

相关文章