Updating Vue 2 to Vue 3

huangapple go评论57阅读模式
英文:

Updating Vue 2 to Vue 3

问题

我有一个旧的Vue 2项目,我们正在迁移到Vue 3,它使用了Bootstrap,考虑到它的旧版本与Vue 3不兼容,所以我最终移除了它。除了这个错误之外,一切似乎都正常,错误信息如下:

未找到此依赖项:
* vue 在 ./src/main.js、./src/api/store.js 和其他 3 处

要安装它,可以运行:npm install --save vue

我使用了vue update来更新到Vue 3,使用npm update升级了一些依赖项,并且第一次在npm命令中使用了--legacy-peer-deps,之后删除了main.js中的Bootstrap导入后,一些错误已被解决。我搜索了一下,但似乎找不到解决方案,因为我在Vue 3上的经验有限,所以非常感谢任何帮助。

这是我的main.js
Updating Vue 2 to Vue 3

这是我初始化应用程序的部分,Vue更新之前曾正常运行:
Updating Vue 2 to Vue 3

这是package.json中关于Vue的部分:
Updating Vue 2 to Vue 3

/编辑/

我将import Vue 更改为vue createApp,在终端中出现了一些错误,终端告诉我需要更新vue-loader到最新版本,我照做了,但现在出现了这个错误。

为了确保至少能够加载app.vue,我已经删除了几乎所有的Vue.use项,然后可以从那里继续。我正在遵循这个教程:链接到教程

Updating Vue 2 to Vue 3

即使在Webpack配置文件中有VueLoaderPlugin,我仍然遇到了这个问题:

const VueLoaderPlugin = require('vue-loader/lib/plugin')

Updating Vue 2 to Vue 3

英文:

I have an old Vue 2 project that we are migrating to Vue 3, it had bootstrap which I ended up removing considering its old versions don't work really well with vue 3. Everything else seems fine except this error,

This dependency was not found:

* vue in ./src/main.js, ./src/api/store.js and 3 others

To install it, you can run: npm install --save vue

I used vue update to update to vue 3, npm update to upgrade some dependencies, and had to use --legacy-peer-deps with the npm commads the first time, I had some errors which were removed after removing bootstrap imports from main.js. I have looked around, can't seem to find the solution for this, haven't worked with Vue3 a lot, any help would be appreciated thanks.
<br />
This is my main.js
Updating Vue 2 to Vue 3

This is me initializing app --- used to work before vue update

Updating Vue 2 to Vue 3

This is package.json vue
Updating Vue 2 to Vue 3

/Edit/

I changed import Vue to vue createApp, had some errors in terminal and terminal told me to update vue-loader to latest version, which I did and now I'm getting this error.
I have removed almost all of Vue.use items to make sure atleast app.vue loads and then I can move on from there. I'm following this tutorial

https://blog.logrocket.com/refactoring-vue-2-apps-vue-3/

Updating Vue 2 to Vue 3

I'm getthing this issue even though VueLoaderPlugin is in webpack config file
<br />

const VueLoaderPlugin = require(&#39;vue-loader/lib/plugin&#39;)

Updating Vue 2 to Vue 3

答案1

得分: 1

这只是Vue 3中不再像以前那样工作。import Vuenew Vue()已被替换为:

import { createApp } from 'vue';

const app = createApp(App);

Vue 3不是Vue 2的直接替代品;你可能需要阅读一些重大变更

英文:

It simply doesn't work like that anymore in Vue 3. import Vue and new Vue() have been replaced by:

import { createApp } from &#39;vue&#39;;

const app = createApp(App);

Vue 3 isn't a drop-in replacement for Vue 2; there's a number of breaking changes you should probably read up on.

huangapple
  • 本文由 发表于 2023年3月15日 20:50:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744959.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定