Vue3 script setup

以下是 Vue3

  • 响应式工具链:支持 reactivecomputedwatch 等组合式 API,与标准写法一致。

  • 3. 组件通信

    • Props 声明:使用 defineProps 宏(支持运行时声明和 TypeScript 类型):
      
      
    • 事件发射:通过 defineEmits
      
      

    4. 依赖注入

    • 直接使用 provide/inject
      
      

    5. 生命周期钩子

    • 直接导入使用(如 onMounted):
      
      

    6. 动态组件与异步

    • 动态组件:通过 :is 绑定组件名或导入的组件对象:
      
      
      
    • 异步组件:配合 defineAsyncComponent
      
      

    7. 高级特性

    • 暴露组件实例:通过 defineExpose 暴露特定属性:
      
      
    • 属性透传:使用 useAttrs() 访问非 props 的 attribute:
      
      

    8. 与选项式 API 对比

    场景

    你可能感兴趣的:(Vue3,typescript,前端,前端,Vue3)