• VUE父组件传递子组件


            背景:父组件传递值给子组件是指,如何把在父组件页面中的数据传递给写在当前父组件页面的子组件页面中

    知识点

    1.在子组件的页面中使用props,声明好准备要传过来的字段

    2.在父组件页面中的子组件标签上写要传递过来的字段和值,并且要与在子组件声明的字段名一致

    3.父组件传递非props属性值,是通过$attrs对象传递的

    实战例子:

    父组件

    1. <template>
    2. <child-message class="abc" :title="title" :content="content">child-message>
    3. template>
    4. <script>
    5. import ChildMessage from "./ChildMessage";
    6. export default {
    7. name: "ParentTest",
    8. components: {ChildMessage},
    9. data(){
    10. return{
    11. title: "我是标题",
    12. content: "我是内容"
    13. }
    14. }
    15. }
    16. script>
    17. <style scoped>
    18. style>

    子组件

    1. <template>
    2. <div>
    3. <h2 :class="$attrs.class">{{title}}h2>
    4. <p>{{content}}p>
    5. div>
    6. template>
    7. <script>
    8. export default {
    9. name: "ChildMessage",
    10. //传递过程中props起到关键作用,主要是用于声明好父组件传过来的字段与在子组件页面中能对应上
    11. //注意props的书写方式有很多种
    12. // props:['title','content'],数组形式
    13. props:{
    14. //对象形式
    15. // title: String,
    16. // content: String
    17. title:{
    18. type: String,
    19. required: true
    20. },
    21. content:{
    22. type: String,
    23. required: true
    24. }
    25. },
    26. data(){
    27. return{
    28. }
    29. }
    30. }
    31. script>
    32. <style scoped>
    33. style>

     

  • 相关阅读:
    应用软件安全编程--21避免使用不安全的哈希算法
    高项 08 项目质量管理
    动态 SQL
    java中volatile解决可见性和有序性问题
    BI工具-DataEase(1) 安装
    redis 支持ipv6和ipv4设置方法
    十大券商:“推土机行情”再现
    mongodb
    C语言C位出道心法(三):共用体|枚举
    Webots将节点复制到不同工程中
  • 原文地址:https://blog.csdn.net/qq_40943363/article/details/127417458