setupSFC
稳定性:
实验性 ⚠️ 实验性功能,风险自负TIP
如果你使用的是 setupSFC,则不能禁用 defineRender。
| 特性 | 支持 |
|---|---|
| Vue 3 | ✅ |
| Nuxt 3 | ✅ |
| Vue 2 | ✅ |
| TypeScript / Volar | ✅ |
安装
ts
// vite.config.ts
import Vue from '@vitejs/plugin-vue'
import VueMacros from 'vue-macros/vite'
export default defineConfig({
plugins: [
VueMacros({
plugins: {
vue: Vue({
include: [/\.vue$/, /\.setup\.[cm]?[jt]sx?$/],
// ⬆️ 需要添加 setup 模式
}),
},
}),
],
})ts
import Vue from 'unplugin-vue/rollup'
import VueMacros from 'vue-macros/rollup'
export default defineConfig({
plugins: [
VueMacros({
plugins: {
vue: Vue({
include: [/\.vue$/, /\.setup\.[cm]?[jt]sx?$/],
// ⬆️ 需要添加 setup 模式
}),
},
}),
],
})🚧🚧基本用法
tsx
// Foo.setup.tsx
defineProps<{
foo: string
}>()
defineEmits<{
(evt: 'change'): void
}>()
export default () => (
<div>
<h1>Hello World</h1>
</div>
)Volar 配置
jsonc
{
"vueCompilerOptions": {
"plugins": ["vue-macros/volar"],
},
}
Kevin Deng
zhiyuanzmj
Leo
Alex
Lzzzs