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導入組件了
很好的css3的loading樣式,下周記得在代碼中補上圓點轉圈的loading,哈哈