1. 自定义plugin.js

export default{
  install(Vue,options);
  {
      Vue.prototype.toStringTwo=(str)=>(
        ('0000'+String(str)).slice(-2)  
     )
  }
}

2.入口js

import Vue from  'vue';
import MyPlugin from './plugin';

Vue.use(MyPlugin);

new Vue({
    //...
})

//即可在各组件调用方法toStringTwo

demo 把loading组件变成插件,这样不用再import导入组件了

vue plugin 插件编写以loading为例

很好的css3的loading样式,下周记得在代码中补上圆点转圈的loading,哈哈

 

相关文章:

  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2021-04-03
  • 2022-12-23
  • 2021-05-07
  • 2021-06-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案