vue3 和 vue2 的区别

时间:2021-08-29 20:33:12   收藏:0   阅读:5

增加特性

  1. composition API:
    • setup():
      • 是composition API 的入口函数
      • 仅初始化时执行一次。(具体是在beforecreate之前执行。此时的this为undefined,所以在setup()无法使用this获取数据)
      • 所有的compostion API都写在 setup() 中。
      • 参数有props和context,说明如下:
        • props:作用是 父组件向子组件传递的数据
        • context:可以解构成{attrs,slot,emit},分别对应vue2中的是:this.$attrs 、 this.$slot 、 this.$emit
      • 返回值为对象,可以在模版中使用。
      • 如果混合了vue2语法,
        • setup中定义的变量和方法优先级更高。
        • method和data可以使用setup中定义的变量和方法。

原文:https://www.cnblogs.com/zxn-114477/p/15196714.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!