//1.安装unplugin-auto-import
npm install unplugin-auto-import -D
//或者
yarn add unplugin-auto-import -D

2.在vite中配置unplugin-auto-import

//vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports:['vue','vue-router']
    })
  ]
})

3.在vue文件中,即可

<script setup lang="ts">
    onMounted(()=>{
        console.log('onMounted')
    })
</script>
Logo

前往低代码交流专区

更多推荐