跳到正文

exportProps NPM Version ​

稳定性: 实验性 ⚠️ 实验性功能,风险自负

在 Vue 中使用 Svelte 风格声明 props。

特性支持
Vue 3✅
Nuxt 3?
Vue 2✅
Volar Plugin✅

前置条件 ​

要使用此功能,需要 Reactivity Transform, 但在 Vue Macros 中已经默认启用。

export let 将编译为 defineModel,该功能在 Vue 3.4+ 中受支持。

用法 ​

使用导出语法来声明 props。

vue
<script setup lang="ts">
export let 
foo
: string
export const
bar
: number = 1 // 带有默认值
</script>

Volar 配置 ​

tsconfig.json
jsonc
{
  "vueCompilerOptions": {
    "plugins": ["vue-macros/volar"],
  },
  "vueMacros": {
    "exportProps": true,
  },
}

贡献者

页面历史

用 ❤️ 发电