Vue定义全局变量

定义
import Vue from 'vue'
import router from './router'
import App from './App.vue'

import './plugins/vueamap.js' //  vue-amap 高德地图
import './plugins/element.js' //  elemnt组件
import {post,get,put,deletes,toJson,isEmpty} from './plugins/http.js' // 请求方式中间件
import {api} from './plugins/api.js'  // API 链接
import {formatDate,formatGoods} from './plugins/function.js' // 公共方法
import '../public/fonts/iconfont.css' // 阿里图标
import '../public/style.css' // 公共CSS

import skeleton from 'vue-skeleton-component' // 骨架


import md5 from 'js-md5'; // md5
import store from './store' // VUEX
import * as qiniu from 'qiniu-js';

import {upload_img} from './components/uploadFile/upload_qny.js';

Vue.use(qiniu);

//定义全局变量
Vue.prototype.$api=api;
Vue.prototype.$post=post;
Vue.prototype.$get=get;
Vue.prototype.$put=put;
Vue.prototype.$delete=deletes;
Vue.prototype.$toJson=toJson;
Vue.prototype.$isEmpty=isEmpty;
Vue.prototype.$md5=md5;
Vue.prototype.$formatGoods=formatGoods;
Vue.prototype.$store=store;
Vue.prototype.$upload_img = upload_img


// 时间格式化
Vue.filter('formatDate', function (time) {
    var date = new Date(time*1000);
    return formatDate(date, 'yyyy-MM-dd hh:mm');
});

Vue.filter('formatDateAuto', function (time,str) {
    var date = new Date(time*1000);
    return formatDate(date, str);
});

Vue.config.productionTip = false

Vue.use(skeleton); // 骨架

// 跳转后返回顶部
router.afterEach(() => {
    window.scrollTo(0,0);
})

new Vue({
    router,
    // store,
    render: h => h(App)
}).$mount('#app')

使用
//使用全局变量请求
      this.$post(this.$api.editGoods + this.$route.params.id, info).then(
        (res) => {
          if (res.code == 200) {
            this.$message.success("修改成功");
          } else {
            this.$message.error(res.msg);
          }
        }
      );

//使用全局变量2
  this.$upload_img(pram).then((res) => {
        console.log("上传七牛云成功返回的图片地址---->", res);
         let obj = new Object();
        obj.url = res;
        this.imgFile.push(obj);
      });  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值