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

相关推荐
小码哥_常31 分钟前
安卓黑科技:实现多平台商品详情页一键跳转APP
前端
killerbasd34 分钟前
还是迷茫 5.3
前端·react.js·前端框架
不会敲代码11 小时前
TCP/IP 与前端性能:从数据包到首次渲染的底层逻辑
前端·tcp/ip
kyriewen2 小时前
奥特曼借GPT-5.5干杯,而你的Copilot正按Token收钱
前端·github·openai
AC赳赳老秦2 小时前
投标合规提效:用 OpenClaw 实现标书 / 合同自动审核、关键词校验、格式优化,降低废标风险
开发语言·前端·python·eclipse·emacs·deepseek·openclaw
kyriewen2 小时前
代码写成一锅粥?3个设计模式让你的项目“起死回生”
前端·javascript·设计模式
不会敲代码12 小时前
从零搭建 AI 日记助手:用 Milvus 向量数据库实现语义搜索
javascript·openai
千寻girling2 小时前
《 Git 详细教程 》
前端·后端·面试
threelab3 小时前
Three.js UV 图像变换效果 | 三维可视化 / AI 提示词
javascript·人工智能·uv
之歆4 小时前
DAY08_CSS浮动与行内块布局实战指南(下)
前端·css