制作一个项目用于研究elementUI的源码

需求:修改el-tooltip的颜色,发现传递参数等方法都不太好用,也可以使用打断点的方式,但也有点麻烦,因此打算直接修改源码,把组件逻辑给修改了

第一步下载源码

源码地址

GitHub - ElemeFE/element: A Vue.js 2.0 UI Toolkit for Web

第二步,创建vue项目

使用vuecli创建vue项目,在src下面创建element-ui文件夹,把上面源码的packages文件夹和src文件夹放入elementui中

第三步,处理导入问题

把复制的源码中引入element-ui的源头指向本地的源码内容,需要修改vue.config.js文件

javascript 复制代码
const { defineConfig } = require('@vue/cli-service')
const path = require("path");
module.exports = defineConfig({
  configureWebpack: {
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
         // "element-ui": "2.14.1",
        "element-ui": path.resolve(__dirname, "src/element-ui"),
      },
    },
  },
  transpileDependencies: true
})

第四步,在main.js中引入

由于上面修改了vue.config.js,这里使用的element-ui都是本地的内容

javascript 复制代码
import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui/src/index';
import 'element-ui/packages/theme-chalk/src/index.scss';
Vue.config.productionTip = false
Vue.use(ElementUI)
new Vue({
  render: h => h(App),
}).$mount('#app')

第五步,解决报错

源码中未使用的变量等其他内容,在npm run serve的时候会报错,所以要关掉。在packages.json文件中的eslintConfig写入下面的rules,关掉提示

javascript 复制代码
"rules": {
      "no-console": "off",
      "no-debugger": "off",
      "no-extra-semi": "off",
      "no-unused-vars": "off",
      "no-undef": "off",
      "no-prototype-builtins": "off",
      "no-useless-escape": "off",
      "vue/multi-word-component-names": "off",
      "vue/no-mutating-props": "off",
      "no-empty": "off",
      "vue/no-unused-components": "off",
      "vue/no-side-effects-in-computed-properties": "off",
      "vue/no-use-v-if-with-v-for": "off",
      "no-case-declarations": "off",
      "vue/return-in-computed-property": "off",
      "vue/valid-v-model": "off"
    }

第六步,包的处理

源码中有些地方引入了包/依赖,需要安装一下才能使用源码,这里可以直接复制下面的内容,然后重新npm i

javascript 复制代码
"dependencies": {
    "async-validator": "~1.8.1",
    "core-js": "^3.8.3",
    "deepmerge": "^1.2.0",
    "normalize-wheel": "^1.0.1",
    "resize-observer-polyfill": "^1.5.0",
    "throttle-debounce": "^1.0.1",
    "vue": "^2.6.14"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@babel/eslint-parser": "^7.12.16",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-service": "~5.0.0",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3",
    "sass": "^1.35.2",
    "sass-loader": "^10.1.1",
    "vue-template-compiler": "^2.6.14"
  },

之后直接使用组件的内容,而且还可以直接修改源码就能看到效果。便于研究源码内容和运行原理

相关推荐
hachi03138 分钟前
Vue中input disabled时点击事件不触发怎么办?
javascript·vue.js·ecmascript
漫天黄叶远飞24 分钟前
别再把对象当“字典”!JS 零基础也能看懂的“属性账本”拆解笔记
javascript
华仔啊27 分钟前
20个CSS实用技巧,10分钟从小白变大神!
前端·css
起名时在学Aiifox29 分钟前
Vue3 + Element Plus 表格排序实战:基于状态字段的智能排序方案
前端·javascript·vue.js·element plus
再吃一根胡萝卜33 分钟前
从 Element UI 到 Element Plus:el-table 大数据量性能为何下降了?
前端
转转技术团队35 分钟前
转转UI自动化走查方案探索
前端
yzx99101339 分钟前
基于Flask的智能语音增强系统模拟
前端·javascript·html
青衫码上行44 分钟前
【Java Web学习 | 第14篇】JavaScript(8) -正则表达式
java·前端·javascript·学习·正则表达式
我的虾分发1 小时前
虾分发是一个键打包封装APP内测分发平台
javascript
草帽lufei1 小时前
解锁AI新维度:深入体验Google Antigravity的Gemini3模型
前端·ai编程·gemini