vue cli 环境搭建

1:设置华为云 npm 源路径: npm config set registry https://mirrors.huaweicloud.com/repository/npm/

2:查看源: npm config get registry

3: npm install -g @vue/cli 安装vue cli 客户端

4:查看vue cli 版本 vue --version vue -V

5:vue ui 查看 项目创建页面

vue3+ ts 使用vuecli 创建项目启动报错 ERROR in src/router/index.ts:1:64

TS7016: Could not find a declaration file for module 'vue-router'. './node_modules/vue-router/index.js' implicitly has an 'any' type.

Try npm i --save-dev @types/vue-router if it exists or add a new declaration (.d.ts) file containing declare module 'vue-router';

> 1 | import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

| ^^^^^^^^^^^^

2 | import HomeView from "../views/HomeView.vue";

解决办法

1:在src 下 新建 shims-vue.d.ts

2:在router 下的 index.ts 中添加 type RouteRecordRaw = typeof RouteRecordRaw; 这个一句代码到 const routes: Array<RouteRecordRaw> 之前

=================================

6:安装 axios前后端交互工具 npm install -g axios

7: vue2 安装使用elementui

npm install -g element-ui

修改main.js

import Vue from "vue";

import App from "./App.vue";

import router from "./router";

import store from "./store";

//引入样式

import ElementUI from "element-ui";

import "element-ui/lib/theme-chalk/index.css";

Vue.config.productionTip = false;

//使用ElementUI

Vue.use(ElementUI);

new Vue({

router,

store,

render: (h) => h(App),

}).$mount("#app");

8:vue3 安装 element-plus

npm install -g element-plus

修复 "Cannot find module 'element-plus' or its corresponding type declarations" 错误

如果使用 TypeScript,需要添加类型声明:

对于 Vue 3 + Element Plus:

// 在 tsconfig.json 中

{

"compilerOptions": {

"types": "element-plus/global"

}

}

或在 shims-vue.d.ts 中添加:

// shims-vue.d.ts

declare module 'element-plus' {

import { Plugin } from 'vue'

const ElementPlus: Plugin

export default ElementPlus

}

对于 Vue 2 + Element UI:

npm install @types/element-ui

相关推荐
lichenyang45310 小时前
Docker 学习笔记(一):为什么需要镜像、容器和仓库?
前端
kyriewen10 小时前
别再对着 TypeScript 报错发呆了:我把 10 个最常见的红色波浪线翻译成了人话
前端·javascript·typescript
IT_陈寒10 小时前
SpringBoot自动配置的坑,我的API突然就404了
前端·人工智能·后端
free3511 小时前
从 0 实现一个 Tiny JavaScript VM:项目架构拆解
javascript
暴走的小呆11 小时前
Vue 2 中 Object 的变化侦测:从 getter/setter 到 Dep、Watcher、Observer
vue.js
奇奇怪怪的11 小时前
Embedding 模型 10+ 横向评测
前端
陈广亮11 小时前
Monorepo 从 0 到 1 实操指南 2026 版:pnpm catalogs + Turborepo 2.x + changesets 全链路
前端
子兮曰11 小时前
OpenMontage 深度解剖:你的 AI 编程助手,其实是个视频工作室
前端·后端·ai编程
敲代码的鱼11 小时前
PDF 预览与签名批注写回 支持安卓 iOS 鸿蒙 UTS插件
android·前端·ios