zoukankan      html  css  js  c++  java
  • 利用Vue的插件机制,实现项目公共代码管理

    import Vue from "vue";
    import axios from "axios";
    import { apis } from "@/static/js/apis.js";
    // import NoData from "@/components/NoData.vue";
    
    
    let myVuePlugin = new Object();
    myVuePlugin.install = function(Vue) {
      /**
       *  接口全局化
       * */
      Vue.prototype.apis = apis;
      /**
       *  get 请求
       *  @params String url
       *  @params Object params
       *  @use this.get(url,params:{}).then(fn).catch(fn)
       * */
      Vue.prototype.get = axios.get;
      /**
       *  post 请求
       *  @params String url
       *  @params Object params
       *  @use this.post(url,{}).then(fn).catch(fn)
       * */
      Vue.prototype.post = axios.post;
      /**
       *  post 请求
       *  @params String url
       *  @params Object params
       *  @use this.post(url,{}).then(fn).catch(fn)
       * */
      Vue.prototype.changeRouter = function(path) {
        this.$router.push({
          path,
        });
      };
      /**
       *  全局无数据组件
       * */
      // Vue.component('NoData', NoData);
      Vue.component('NoData', () => import("@/components/NoData.vue"));
    };
    
    Vue.use(myVuePlugin);
  • 相关阅读:
    jQuery-css
    了解jQuery
    jQuery属性
    jQuery常用效果
    jQuery_$工具方法
    jQuery选择器
    jQuery核心对象
    $
    jQuery两把利器
    JavaScriptDOM
  • 原文地址:https://www.cnblogs.com/lguow/p/13361764.html
Copyright © 2011-2022 走看看