unplugin / unplugin-auto-import

Auto import APIs on-demand for Vite, Webpack and Rollup
MIT License
3.29k stars 198 forks source link

自动注册vue无效 #96

Closed cuiqg closed 2 years ago

cuiqg commented 2 years ago

VUE CLI (4.5.15) vue.config.js

const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const Icons = require('unplugin-icons/webpack')
const IconsResolver = require('unplugin-icons/resolver')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')

module.exports = {
     configureWebpack: {
        plugins: [
            AutoImport({
                imports: ['vue', 'vue-router'],
                resolvers: [ElementPlusResolver()]
            }),
            Components({
                resolvers: [
                    ElementPlusResolver(),
                    IconsResolver({
                        prefix: false,
                        enabledCollections: ['ep']
                    })
                ]
            }),
            Icons({
                autoInstall: true
            })
        ]
    }
}

App.vue

<template>
  <el-config-provider :locale="locale" :button="button">
    <el-container>
      <Header />
      <el-container>
        <Sidebar />
        <Main />
      </el-container>
    </el-container>
  </el-config-provider>
</template>

<script>
import zhCN from "element-plus/lib/locale/lang/zh-cn";

export default defineComponent({
  name: "App",
  components: {},
  setup() {
    const locale = ref(zhCN);
    const button = reactive({
      autoInsertSpace: true,
    });

    return {
      locale,
      button,
    };
  },
});
</script>

会提示: defineComponent ref reactive 未定义

enpitsuLin commented 2 years ago

你的配置有误 这样是仅自动引入vue的默认导出参考presetvue-composition-api.ts文件

VIISEVEN27 commented 2 years ago

请问问题解决了吗,可以参考一下正确的配置吗?

cuiqg commented 2 years ago

请问问题解决了吗,可以参考一下正确的配置吗?

没有弄了

VIISEVEN27 commented 2 years ago

你的配置有误 这样是仅自动引入vue的默认导出参考presetvue-composition-api.ts文件

可以具体说一下应该怎么配置吗

chenbingchang commented 2 years ago

你的配置是正确的。之所以提示未定义,是因为需要运行项目后才能监测到你需要全局引入vue的api,然后才会在auto-import.d.ts里面有相应的声明,这样才不会提示未定义。 下面这张图是我运行项目(npm run start)后声明文件自动加上的 image