Skip to content

templateRef NPM Version

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

自动推断 templateRefuseTemplateRef (vue3.5) 的类型.

FeaturesSupported
Volar Plugin

基本用法

vue
<script setup lang="ts">
import { 
templateRef
} from '@vueuse/core'
import {
Comp
} from './Comp.ts'
const
comp
=
templateRef
('comp')
comp
.
value
?.
foo
</script> <template> <
Comp
ref
="
comp
" />
</template>
ts
import { defineComponent } from 'vue'

export const Comp = defineComponent({
  setup() {
    return { foo: 1 }
  },
})

Volar 配置

jsonc
// tsconfig.json
{
  "vueCompilerOptions": {
    "plugins": ["unplugin-vue-macros/volar"],
    "vueMacros": {
      "templateRef": {
        /**
         * @default ["templateRef", "useTemplateRef"]
         */
        "alias": ["templateRef"],
      },
    },
  },
}

贡献者

The avatar of contributor named as Kevin Deng Kevin Deng
The avatar of contributor named as gaokefei gaokefei

页面历史