• VUE3 ref,props,生命周期


    1.--ref属性

     1.1代码

    1.1.1子表

    1. <template>
    2. <div class="person">
    3. <h1>中国</h1>
    4. <h2 ref="title2">北京</h2>
    5. <h3>尚硅谷</h3>
    6. <button @click="showLog">点我输出h2这个元素</button>
    7. </div>
    8. </template>
    9. <script lang="ts" setup name="Person">
    10. import {ref,defineExpose} from 'vue'
    11. // 创建一个title2,用于存储ref标记的内容
    12. let title2 = ref()
    13. let a = ref(0)
    14. let b = ref(1)
    15. let c = ref(2)
    16. function showLog(){
    17. console.log(title2.value)
    18. }
    19. defineExpose({a,b,c})
    20. </script>
    21. <style scoped>
    22. .person {
    23. background-color: skyblue;
    24. box-shadow: 0 0 10px;
    25. border-radius: 10px;
    26. padding: 20px;
    27. }
    28. button {
    29. margin: 0 5px;
    30. }
    31. li {
    32. font-size: 20px;
    33. }
    34. </style>

    1.1.2父表

    
    
    
    

     2.简单回顾TS

    1.子

    
    
    
    
    
    
    
    
    

     2.TS

    export interface PersonInter {
      id:string,
      name:string,
      age:number
    }
    
    // 一个自定义类型
    // export type Persons = Array
    export type Persons = PersonInter[]

     3.props的使用

    1.1子表

    
    
    
    
    

     1.2父表

    
    
    
    

    2.TS

    // 定义一个接口,用于限制person对象的具体属性
    export interface PersonInter {
      id:string,
      name:string,
      age:number,
    }
    
    // 一个自定义类型
    // export type Persons = Array
    export type Persons = PersonInter[]

    4. 对生命周期的理解

    1.vue3


    1. 子表

    
    
    
    
    

    2.父表

    
    
    

  • 相关阅读:
    VS+Qt+opencascade三维绘图stp/step/igs/stl格式图形读取显示
    嵌入式面试3(C++相关)
    centos7安装zabbix 5.0
    虚幻引擎中增强输入映射中鼠标输入无反应,怎么办?
    java计算机毕业设计基于安卓Android的校园跑腿代购app
    Java调用Linux SCP操作(SCPClient)
    基于神经网络匹配度的模拟电路故障诊断
    I O 流
    容器启动报错
    vue中对axios的二次封装和节流与防抖
  • 原文地址:https://blog.csdn.net/TA016422/article/details/138012614