自动引入 composition api,不需要再手动引入。
github地址:https://github.com/antfu/unplugin-auto-import
下载
npm i unplugin-auto-import -D
修改vite.config.ts文件
import AutoImport from 'unplugin-auto-import/vite' export default defineConfig({ plugins: [vue(),AutoImport({ imports: ['vue'], dts: 'src/auto-import.d.ts' })] })
配置完毕后保存,此时会自动生成一个 auto-import.d.ts 的文件
现在我们可以在项目中写入代码, 可以看到我们没有手动引入 ref 也可以在项目中正常使用。
<template> <div> <button @click="flag = !flag">change flag</button> <div>{{ flag }}</div> </div> </template> <script setup lang="ts"> const flag = ref(false); </script> <style lang="less"></style>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)