vue3.3已支持,不需要再安装

安装

npm i -D unplugin-vue-define-options @vue-macros/volar

yarn add -D unplugin-vue-define-options @vue-macros/volar

pnpm add -D unplugin-vue-define-options @vue-macros/volar
// vite.config.ts
import DefineOptions from 'unplugin-vue-define-options/vite'

export default defineConfig({
  plugins: [DefineOptions()],
})

TypeScript支持

// tsconfig.json
{
  "compilerOptions": {
    // ...
    "types": ["unplugin-vue-define-options/macros-global" /* ... */]
  }
}

基本用法

<script setup lang="ts">
import { useSlots } from 'vue'
defineOptions({
  name: 'Foo',
  inheritAttrs: false,
})
const slots = useSlots()
</script>

Volar配置

// tsconfig.json
{
  "vueCompilerOptions": {
    "target": 3, // or 2.7 for Vue 2
    "plugins": [
      "@vue-macros/volar/define-options"
      // ...more feature
    ]
  }
}

更多使用细节请看文档