vue引入的插件,如 element , 都需要提供 install 方法,因为 Vue.use() 方法会调用插件里的 install 方法

    1. import Vue from 'vue'
    2. import Element from 'element-ui'
    3. Vue.use(Element)

    类似的
    全局组件也是同样的做法,在 install 方法里面 进行 组件 注册

    1. import ColorIconComponents from './iconColor.vue'
    2. const ColorIcon = {
    3. install: function (Vue) {
    4. Vue.component('ColorIcon', ColorIconComponents)
    5. }
    6. }
    7. export default ColorIcon

    数组对象等绑定自定义方法

    1. export default {
    2. install(Vue) {
    3. // 数组对象排序 asc-升序 des-降序
    4. Array.prototype.sortListObjByKey = function (key, order = 'asc') {
    5. const that = this
    6. const comparefn = (obj1, obj2) => {
    7. if (order === 'asc') {
    8. return obj1[key] - obj2[key]
    9. } else {
    10. return obj2[key] - obj1[key]
    11. }
    12. }
    13. return that.sort(comparefn)
    14. }
    15. }
    16. }
    1. import customFn from "./libs/customFn";
    2. Vue.use(customFn)