当前位置: 首页 > 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 效果 

相关文章:

  • Deepoc大模型重构核工业智能基座:混合增强架构与安全增强决策技术​
  • 【文件】Linux 内核优化实战 - fs.inotify.max_user_instances
  • Redis中的bigkey的介绍及影响
  • 在训练词编码模型使用mask还是自回归,在训练生成大模型采用mask还是自回归?
  • 601N1 icm45696 串口python读取及显示
  • GO 语言学习 之 代码风格
  • Towards Generalizable Diabetic Retinopathy Grading in Unseen Domains
  • 【C++】哈希表的实现(链地址法)
  • Redis哨兵模式深度解析与实战部署
  • Clickhouse原理剖析
  • Elasticsearch 搜索的流程
  • 最新发布 | “龙跃”(MindLoongGPT)大模型正式发布!龙跃而起,推动中国方案走向全球智能体前沿
  • 电脑的虚拟内存对性能影响大吗
  • [go] 垃圾回收源码解析
  • MCU双分区方案,如何优雅地获知当前运行分区?
  • 新高考需求之一
  • pyhton基础【15】函数进阶一
  • 从厨房到代码台:用做菜思维理解iOS开发 - Swift入门篇①
  • ADIOS2 介绍与使用指南
  • Vue3 + Vite + TypeScript SVG图标解决方案
  • 设计教学网站推荐/西安外包网络推广
  • 株洲网站建设联系方式/seo网站运营
  • 中信建设有限责任公司国内区事业部招聘/优化疫情二十条措施
  • 做盗版网站会坐牢吗/搜索引擎优化免费
  • javaee是做网站的?/百度官网优化
  • 北京做网站哪家公司最好/安卓手机性能优化软件