vue3:ref reactve 计算属性 组件传值

181 阅读1分钟
  • vue3中 已进入页面就执行这个setup函数 执行顺序比beforcreate快
  • 基本数据类型 使用ref
  • 引用数据类型 使用reactive
  • 任何方法和数据 都需要return出去
  • v-model 这个ref值 是双向数据绑定
  • 修改值需要.value
  • 需要使用的 都需要inport引入
  • 因为vue3代理属性在proxy上 函数使用箭头函数没有this 使用箭头函数就没有这个proxy数据了
  • 所以在vue3不使用箭头函数,如果使用也要const add=(=》{})或是function add(){} image.png

image.png

  • 计算属性 引入 注册
  • import { ref, reactive ,computed, watch ,provide} from "vue"; image.png

image.png

  • 监听器

image.png

image.png

  • 父子传值

image.png

image.png

image.png

image.png

  • 爷孙传值

image.png

image.png