运行vue2源码,最适合的nodejs版本和yarn版本

Node.js 版本

  • Node.js 14.x:这是一个长期支持(LTS)版本,在许多 Vue 2 项目开发和部署中被广泛采用。它提供了良好的性能和稳定性,并且与大多数 Vue 2 生态系统的工具和依赖兼容。
perl 复制代码
# 使用 Node.js 14.x
nvm use 14

Yarn 版本

对于 Yarn,建议使用 Yarn 1.x(也称为 Yarn Classic)。Yarn 1.x 是一个成熟且广泛使用的包管理工具,在 Vue 2 项目开发中具有良好的兼容性和稳定性。

sql 复制代码
npm install -g yarn@1
yarn -v
yarn add typescript@latest --dev

忽略警告

如果更新依赖或者指定版本都不可行,且这个警告不会影响项目的正常运行,你可以选择忽略这个警告。不过,这只是一个临时的解决方案,建议你在合适的时机对依赖进行升级。

在运行项目时,可以使用 --no-fund--no-audit 参数来减少不必要的警告输出:

使用 npm

css 复制代码
npm install --no-fund --no-audit

使用 yarn

css 复制代码
yarn install --no-fund --no-audit

ts报错

swift 复制代码
Type '{ component: () => Promise<Component<DefaultData<never>, DefaultMethods<never>, DefaultComputed, Record<string, any>>>; }' is not assignable to type 'void | Promise<EsModule<Component<DefaultData<never>, DefaultMethods<never>, DefaultComputed, Record<string, any>>>> | { component: Promise<EsModule<Component<DefaultData<never>, DefaultMethods<...>, DefaultComputed, Record<...>>>>; loading?: VueConstructor<...> | ... 3 more ... | undefined;

解决方案:

typescript

typescript 复制代码
import { Component } from 'vue';

// 假设 EsModule 是一个包装组件的类型
type EsModule<T> = { default: T };

type AsyncComponent = () => {
  component: Promise<EsModule<Component>>;
  loading?: any;
  error?: any;
  delay?: number;
  timeout?: number;
};

const b: AsyncComponent = () => ({
  // 直接返回 Promise<EsModule<Component>>
  component: new Promise<EsModule<Component>>((res, rej) => {
    res({ default: { template: "" } });
  }),
  // 你可以根据需要添加 loading、error、delay 和 timeout 属性
});

解释

  • 定义了 EsModule 类型,用于包装组件。
  • 确保 component 属性直接返回 Promise<EsModule<Component>>,而不是返回 Promise 的函数。
  • res({ default: { template: "" } }) 保证了返回的 Promise 解析为一个具有 default 属性的对象,该属性包含组件定义。
相关推荐
@yanyu66614 小时前
登录注册功能-明文
vue.js·springboot
滕青山18 小时前
在线PDF拆分工具核心JS实现
前端·javascript·vue.js
光影少年1 天前
前端在页面渲染优化和组件优化经验?
前端·vue.js·react.js·前端框架
李白的天不白1 天前
VUE依赖配置问题
前端·javascript·vue.js
小智社群1 天前
获取贝壳新房列表
前端·javascript·vue.js
一 乐1 天前
茶叶商城|基于springboot + vue茶叶商城系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·茶叶商城系统
吴声子夜歌1 天前
Vue3——Pinia状态管理
javascript·vue.js·pinia
追风筝的人er2 天前
SpringBoot+Vue3 企业考勤如何处理法定假期?节假日方案、调休补班与工作日判断链路拆解
前端·vue.js·后端
编程老船长2 天前
解决不同项目需要不同 Node.js 版本的问题
前端·vue.js
xiaogg36782 天前
spring oauth2 单点登录
java·vue.js·spring