main.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //全局随机数重写
  2. const random = Math.random;
  3. Math.random = (a = 0, b = 1, c = 6) => {
  4. return (random() * (b - a) + a).toFixed(c) - 0;
  5. };
  6. import Vue from 'vue';
  7. //全局接口请求
  8. import $http from "./api/index.js";
  9. Vue.prototype.$http = $http;
  10. //管理数据状态
  11. import store from './script/store';
  12. Vue.prototype.$store = store;
  13. //ui框架
  14. import {
  15. Image, //图片
  16. Rate,
  17. Input,
  18. InfiniteScroll,
  19. Button
  20. } from 'element-ui';
  21. import 'element-ui/lib/theme-chalk/index.css'
  22. Vue.use(Image);
  23. Vue.use(Rate);
  24. Vue.use(Input);
  25. Vue.use(InfiniteScroll);
  26. Vue.use(Button);
  27. import VueTouch from"vue-touch";
  28. VueTouch.config.swipe = {direction: 'horizontal' };
  29. Vue.use(VueTouch, {name:'v-touch'});
  30. import 'animate.css';
  31. import './assets/css/main.less';
  32. //路由
  33. import router from './script/router';
  34. import mainTitle from './components/title.vue';
  35. Vue.component("mainTitle",mainTitle);
  36. import preview from "./components/preview.vue";
  37. Vue.component("preview",preview);
  38. //防止多次触发执行 函数
  39. Vue.prototype.$timeFun = (time = 500) => {
  40. let o = null;
  41. return (fun, t) => {
  42. clearTimeout(o);
  43. o = setTimeout(fun, t || time);
  44. }
  45. }
  46. //全局过滤器
  47. Vue.filter("host",src=>{
  48. src += "";
  49. const x = src.slice(0, 1);
  50. switch (src.slice(0, 7)) {
  51. case 'http://':
  52. case 'https:/':
  53. return src;
  54. break;
  55. default:
  56. return `/mtsy${x == '/' ? '' : '/'}${src}`;
  57. break;
  58. }
  59. });
  60. Vue.filter("hostList",src=>{
  61. src += "";
  62. const x = src.slice(0, 1);
  63. switch (src.slice(0, 7)) {
  64. case 'http://':
  65. case 'https:/':
  66. return [src];
  67. break;
  68. default:
  69. return [`/mtsy${x == '/' ? '' : '/'}${src}`];
  70. break;
  71. }
  72. });
  73. import App from './App.vue';
  74. new Vue({
  75. router,
  76. render: h => h(App)
  77. }).$mount('#app');