this.array.ForEach Vue CLI 找不到依赖项

this.array.ForEach dependencies not found with VueCLI

这是我的代码。我正在使用 VueCLI。

造成问题的行是this.slides.forEach(..

我遇到的错误是 dependencies not found(下面是完整错误)。

当我安装缺少的依赖项时 npm install --save core-js/modules/es.array.for-each core-js/modules/web.dom-collections.for-each 我有一个 es.array.for-each does not contain a package.json file 错误

然后我在错误中描述的位置创建了 package.json 文件。我 运行 npm install 但我有同样的 package.json not found 错误。

这里有什么问题的线索吗?

<template>
    <div>
        <slot>

        </slot>
    </div>
</template>

<script>
export default {
    data (){
        return{
            index: 0,
            slides: []
        }
    },
    mounted(){
        this.slides = this.$children

        this.slides.forEach((slide, i) => {
            slide.index = i
        })
    }
}
</script>

<style lang="css">

</style>

 ERROR  Failed to compile with 2 errors                                                                                                                                                                 10:39:10 AM
These dependencies were not found:

* core-js/modules/es.array.for-each in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Carousel/Carousel.vue?vue&type=script&lang=js&
* core-js/modules/web.dom-collections.for-each in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Carousel/Carousel.vue?vue&type=script&lang=js&

To install them, you can run: npm install --save core-js/modules/es.array.for-each core-js/modules/web.dom-collections.for-each

npm ERR! code ENOLOCAL
npm ERR! Could not install from "core-js\modules\es.array.for-each" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     User\...\AppData\Roaming\npm-cache\_logs20-02-15T15_49_17_958Z-debug.log

找到答案。

npm install --save-dev @vue/cli @vue/cli-service-global core-js@3

成功了!我认为 core-js@2

存在一些问题