当前位置: 首页 > news >正文

vue3整合element-plus

 

为项目命名  选择vue 框架 选择TS 

启动测试: npm run dev 

开始整合 element-plus

npm install element-plus --save
npm install unplugin-vue-components unplugin @vitejs/plugin-vue --save-dev

  修改main.ts

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'const app = createApp(App)
app.use(ElementPlus)
app.mount('#app')

 修改vite.config.ts

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'export default defineConfig({plugins: [vue(),Components({resolvers: [ElementPlusResolver()],dts: true, // 自动生成一个 components.d.ts 文件,帮助 TS 识别}),],
})

检查 tsconfig.app.json

{"files": [],"references": [{ "path": "./tsconfig.app.json" },{ "path": "./tsconfig.node.json" }]
}

修改 tsconfig.app.json

{"extends": "@vue/tsconfig/tsconfig.dom.json","compilerOptions": {"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",/* Linting */"strict": true,"noUnusedLocals": true,"noUnusedParameters": true,"erasableSyntaxOnly": true,"noFallthroughCasesInSwitch": true,"noUncheckedSideEffectImports": true,"types": ["element-plus/global"]},"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
}

修改 App.vue

<template><Login/>
</template><script setup lang="ts">
import Login from './components/Login.vue'
</script><style scoped>
</style>

 Login.vue

<template><div class="login-container"><el-card class="box-card"><template #header><div>用户登录</div></template><el-form :model="form" :rules="rules" ref="formRef"><el-form-item label="用户名" prop="username"><el-input v-model="form.username" /></el-form-item><el-form-item label="密码" prop="password"><el-input v-model="form.password" type="password" show-password /></el-form-item><el-form-item><el-button type="primary" @click="onSubmit">登录</el-button><el-button @click="onReset">重置</el-button></el-form-item></el-form></el-card></div>
</template><script setup lang="ts">
import { ref } from "vue";const form = ref({ username: "", password: "" });
const rules = {username: [{ required: true, message: "请输入用户名", trigger: "blur" }],password: [{ required: true, message: "请输入密码", trigger: "blur" }],
};
const formRef = ref();function onSubmit() {if (formRef.value) {formRef.value.validate((valid) => {if (valid) alert("提交成功");});}
}function onReset() {if (formRef.value) {formRef.value.resetFields();}
}
</script><style scoped>
.login-container {display: flex;justify-content: center;align-items: center;height: 100vh;
}
.box-card {width: 400px;
}
</style>

npm run dev 效果 

http://www.lqws.cn/news/489871.html

相关文章:

  • Linux部署Sonic前后端(详细版)(腾讯云)
  • 老项目Android开发环境搭建的困境与解决之道-优雅草卓伊凡
  • 【数据库复习】
  • 用 EXCEL/WPS 实现聚类分析:赋能智能客服场景的最佳实践
  • 使用 catthehacker/ubuntu Docker 镜像部署 GitHub Actions 本地运行环境
  • 【C++项目】基于IPV4的流媒体广播
  • Redis中的bigkey的介绍及影响
  • 能耗管理新革命:物联网实现能源高效利用
  • 在 Java 中生成 PDF 缩略图(教程)
  • 华为OD 机试 2025-数字序列比大小
  • 麒麟系统上设置Firefox自动化测试环境:指定Marionette端口号
  • vue | vue-macros 插件升级以及配置
  • 拼多多API限流机制破解:分布式IP池搭建与流量伪装方案
  • Elasticsearch API访问权限控制:禁用外部端点访问
  • 家电 EPS 内衬,重庆制造如何保障家电安全?​
  • Android的TabLayout对象添加select监听器,使得和mViewPage联动
  • JavaScript防抖与节流:优化高频事件处理
  • minidocx: 一个轻量级的跨平台的C++操作word的开源库
  • Python----OpenCV(图像増强——图像平滑、均值滤波、高斯滤波、中值滤波、双边滤波)
  • ScopedValue vs ThreadLocal:谁更适合微服务上下文管理
  • PyTorch 张量(Tensors)全面指南:从基础到实战
  • WebSocket长连接在小程序中的实践:消息推送与断线重连机制设计
  • 全链接神经网络,CNN,RNN各自擅长解决什么问题
  • qt常用控件--02
  • uniapp+vue3做小程序,获取容器高度
  • 相机标定与3D重建技术通俗讲解
  • <tauri><threejs><rust><GUI>基于tauri和threejs,实现一个3D图形浏览程序
  • UE5 AnimMontage 的混合(Blend)模式
  • npm install时,遇到digital envelope routines::unsupported
  • BlazorWebView微软跨平台浏览器控件,UI组件