Vue页面开发和脚手架开发 Vue2集成ElementUI Vue3集成Element Plus

Element UI&&Element Plus

Element,一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库。https://element.eleme.cn/#/zh-CN/component/installation

Element Plus,基于 Vue 3,面向设计师和开发者的组件库。https://element-plus.org/zh-CN/#/zh-CN

Element UI安装: npm install element-ui --save

Element Plus安装: npm install element-plus --save

页面开发,Vue2集成ElementUI

复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.1" />
    <title>VUE2+ElementUI</title>
    <!-- 引入Element UI的CSS文件 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
    <!-- 引入Element UI的JavaScript库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>

<body>
    <div id="root1" style="background-color: blueviolet;">
        <span>{{msg}}</span>
        <my-title></my-title>
        <user-info></user-info>
    </div>
    <script>
        // 全局组件
        const component1 = Vue.extend({
            template : '<h2>关于VUE的页面</h2>'
        });
        Vue.component('my-title',component1);
        // 局部组件
        const userComponent1 = Vue.extend({
            template: `<div>
                            <p>姓名:{{name}},年龄:{{age}}</p>
                            <el-button type="primary" icon="el-icon-warning" @click='info'>信息</el-button>
                       </div> `,
            data(){
                return {
                    name:'古怪今人',
                    age:'43'
                }
            },
            methods:{
                info(){
                    alert('这里是信息呀~');
                }
            }
        });
        // 实例
        const vueApp1 = new Vue({
            el: '#root1',
            data:{
                msg:'hello vue2!'
            },
            components:{
                'user-info': userComponent1
            }
        });
    </script>
</body>

</html>

页面开发,Vue3集成Element Plus

复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.1" />
    <title>VUE3</title>
    <!-- 引入Element Plus的CSS文件 -->
    <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <!-- 引入Element Plus的JavaScript文件 -->
    <script src="https://unpkg.com/element-plus"></script>
</head>

<body>
    <div id="root1" style="background-color: blueviolet;">
        <el-button type="primary" @click="handleClick1">点击我</el-button>
        <el-button type="info" @click="handleClick2">点击我</el-button>
        <span>{{msg}}</span>
        <my-title></my-title>
        <user-info></user-info>
    </div>
    <script>
        // 全局组件
        const component1 = {
            template: '<h2>关于VUE的页面</h2>'
        };
        // 局部组件
        const userComponent1 = {
            template: `<div>
                            <p>姓名:{{name}},年龄:{{age}}</p>
                            <el-button type="primary" @click='info'>信息</el-button>
                       </div> `,
            data() {
                return {
                    name: '古怪今人',
                    age: '43'
                }
            },
            methods: {
                info() {
                    alert('这里是信息呀~');
                }
            }
        };
        // 实例1
        const vueApp1 = Vue.createApp({
            setup() {
                // 定义点击事件处理函数
                const handleClick1 = () => {
                    alert('1、按钮被点击~');
                };
                return {
                    msg: 'hello vue3!',
                    handleClick1
                }
            },
            methods: {
                handleClick2(){
                    alert('2、按钮被点击~');
                }
            },
            components: {
                'user-info': userComponent1
            }
        });
        // 注册全局组件
        vueApp1.component("my-title", component1);
        // 使用Element Plus组件库
        vueApp1.use(ElementPlus);
        vueApp1.mount("#root1");
    </script>
</body>

</html>

Vue CLI脚手架开发,Vue2集成ElementUI

安装Vue CLI: npm install -g @vue/cli

Element UI安装: npm install element-ui --save

main.js

复制代码
import Vue from 'vue'
import App from './App.vue'


import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'; 
Vue.use(ElementUI);


Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

App.vue

复制代码
<template>
    <div id="app">
        <el-button type="primary" @click="handleClick1">点击我</el-button>
    </div>
</template>

<script>

export default {
    name: 'App',
    components: {
        
    },
    methods:{
        handleClick1(){
            alert('按钮被点击~');
        }
    }
}
</script>

Vite脚手架开发,Vue3集成Element Plus

创建项目: npm init vite@latest <project-name> --template vue

Element Plus安装: npm install element-plus --save

main.js

复制代码
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')

App.vue

复制代码
<template>
    <div>
      <el-button type="primary" @click="handleClick1">点击我</el-button>
    </div>
</template>

<script setup>
    // 定义点击事件处理函数
    const handleClick1 = () => {
            alert('1、按钮被点击~');
    };
</script>
相关推荐
京东零售技术12 分钟前
京东小程序JS API仓颉改造实践
前端
老A技术联盟22 分钟前
从小白入门,基于Cursor开发一个前端小程序之Cursor 编程实践与案例分析
前端·小程序
风铃喵游25 分钟前
构建引擎: 打造小程序编译器
前端·小程序·架构
sunbyte30 分钟前
50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | ThemeClock(主题时钟)
前端·javascript·css·vue.js·前端框架·tailwindcss
小飞悟39 分钟前
🎯 什么是模块化?CommonJS 和 ES6 Modules 到底有什么区别?小白也能看懂
前端·javascript·设计
浏览器API调用工程师_Taylor39 分钟前
AOP魔法:一招实现登录弹窗的全局拦截与动态处理
前端·javascript·vue.js
FogLetter40 分钟前
初识图片懒加载:让网页像"懒人"一样聪明加载
前端·javascript
微客鸟窝41 分钟前
一文搞懂NVM管理Node.js:从安装到实战全攻略
前端
归于尽42 分钟前
Cookie、Session、JWT 的前世今生
前端
程序员辉哥43 分钟前
学会在Cursor中使用Rules生成代码后可以躺平了吗?
前端·后端