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

相关推荐
码云社区18 分钟前
Java在线租房系统源码:VR看房素材、房源图片与内容维护方案
java·vue.js·vr·租房小程序·在线租房·看房租房
cc.ChenLy23 分钟前
无法修改 el-dialog 样式原因及解决办法
javascript·vue.js·elementui
狮子座的男孩1 小时前
html+css基础:31、响应式布局(媒体类型,媒体特性,运算符,常用阈值)
前端·css·经验分享·html·响应式布局·媒体类型/特性·常用阈值
鲸鹏芯海微电子科技 (上海) 有限公司1 小时前
手机直连卫星,射频前端到底要解决什么?
前端·智能手机·低轨卫星·謓泽·鲸鹏芯海·毫米波射频·相控阵芯片
Flynt1 小时前
npm run dev --host 有风险?我把 Vite 这个 9.1 分漏洞复现了一遍
前端·vite
AI开源软件1 小时前
Vue3+SpringBoot3 业务配置统一管理:接管、保存与回退怎样保留有效值
java·前端·vue.js·spring boot·vue·ruoyi office
1-1=01 小时前
Vue 脚手架
前端·javascript·vue.js
Dumbness1 小时前
搜 platform 却给出 Form 表单:离线文档检索把短关键词当成了子串
javascript·node.js
snow@li2 小时前
node:读取本地文件/静态文件服务器/打开Axure原型/prototype-server
前端·node
狮子座的男孩2 小时前
html+css基础:32、BFC(父子元素防止 margin 塌陷,父子元素清除浮动,兄弟元素两栏布局)
前端·css·经验分享·html·bfc·margin塌陷·清除浮动