在项目中需要修改一下element 封装好的组件, 这里记录一下具体流程.

这里需要注意, 直接在项目的node_modules里修改时没有用的, 需要先从git上拉到elementUI的源文件,在本地调试后, 编译, 再把lib文件夹去替换node_mmodules中的对应文件夹.

1. 拉取如图所示的项目

从github上下载源码

https://github.com/ElemeFE/element.git
cd element
npm install
image.png
上图中的lib在原项目中是没有的, 编译后才会出现

2. 修改代码

这里用一个下拉组件select做演示:
修改前:
image.png
现在需要把下拉框的后缀箭头去掉

1. 进入packages文件夹, 找到select文件夹

image.png

image.png
在一个el-input组件中, v-model对应的selectedLabel就是我们要修改的组件:

  1. <el-input
  2. ref="reference"
  3. v-model="selectedLabel"
  4. type="text"
  5. :placeholder="currentPlaceholder"
  6. :name="name"
  7. :id="id"
  8. :autocomplete="autoComplete || autocomplete"
  9. :size="selectSize"
  10. :disabled="selectDisabled"
  11. :readonly="readonly"
  12. :validate-event="false"
  13. :class="{ 'is-focus': visible }"
  14. :tabindex="(multiple && filterable) ? '-1' : null"
  15. @focus="handleFocus"
  16. @blur="handleBlur"
  17. @input="debouncedOnInputChange"
  18. @keydown.native.down.stop.prevent="handleNavigate('next')"
  19. @keydown.native.up.stop.prevent="handleNavigate('prev')"
  20. @keydown.native.enter.prevent="selectOption"
  21. @keydown.native.esc.stop.prevent="visible = false"
  22. @keydown.native.tab="visible = false"
  23. @compositionstart="handleComposition"
  24. @compositionupdate="handleComposition"
  25. @compositionend="handleComposition"
  26. @mouseenter.native="inputHovering = true"
  27. @mouseleave.native="inputHovering = false">
  28. <template>
  29. <span>user</span>
  30. </template>
  31. <template slot="prefix" v-if="$slots.prefix">
  32. <slot name="prefix"></slot>
  33. </template>
  34. <template slot="suffix">
  35. <i v-show="!showClose" :class="['el-select__caret', 'el-input__icon', 'el-icon-' + iconClass]"></i>
  36. <i v-if="showClose" class="el-select__caret el-input__icon el-icon-circle-close" @click="handleClearClick"></i>
  37. </template>
  38. </el-input>

只需要把最下面slot=”suffix”的tempalate删掉.

3. 调试代码

然后运行 npm run dev, 该项目是热编译, 运行后修改代码会自动重新编译.
image.png
就可以看到运行后的效果:

image.png
这里有一点 要注意了 Element这里抛出了一个http://0.0.0.0:8085 直接访问这个地址是访问不到 必须访问http://localhost:8085/ 才行!

3. 修改源码后跟新到项目中

在调试成功后, 执行:
npm run dist
image.png
之后就会在项目中出现一个lib文件夹:
image.png

用生成的lib文件夹去替换你的项目下: D:\your-app\node_modules\element-ui 中的lib
image.png

最后重新运行项目就可以了.