vue 统一配置文件 方便打包后修改请求地址和项目名

在 main.js 主文件中的配置
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router/index'
import ElementUI from "element-ui";
import store from './store'
import "element-ui/lib/theme-chalk/index.css";
import http from './utils/http/http'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
import './assets/all.scss'
import './assets/common.scss'
//重点
import axios from 'axios'

import message from './libs/message.js'
import echarts from "echarts";
import animated from 'animate.css' // npm install animate.css --save安装,在引入
import mixin from "./utils/mixin.js"
Vue.use(animated)
Vue.use(Antd)
Vue.use(ElementUI, {
  size: "small"
});
Vue.config.productionTip = false
Vue.prototype.$message = message
Vue.prototype.$http = http;
Vue.prototype.$echarts = echarts
function setTree(arr, bm, pid, id, mc) {
  const newArr = []
  for (const item of arr) {
    item.selected = item.selected||false
    if(mc && item[mc].indexOf(item[id])== -1){
      item[mc] = `${item[mc]}(${item[id]})`
    }
    if (item[pid] === bm) {
      item.children = setTree(arr, item[id], pid, id, mc)
      newArr.push(item)
    }
  }
  return newArr
}
Vue.prototype.$setTree = setTree
Vue.prototype.$formDate = formDate
Vue.mixin(mixin)

// 引入固定的配置文件 ,然后将字段写入vue对象中
axios.get('/static/config.json').then(res => {
  Vue.prototype.$DWMC = res.DWMC
  Vue.prototype.$DWJC = res.DWJC
  Vue.prototype.$TJCS = res.TJCS
  axios.defaults.baseUrl = res.BASE_URL
  Vue.prototype.BASE_URL = res.BASE_URL
  new Vue({
    el: '#app',
    router,
    store,
    components: {
      App
    },
    template: '<App/>'
  })
})

配置文件 在src 文件外 static\config.json
{
  "BASE_URL":"http://192.168.XX.XX:端口号",
  "DWMC":"项目名成",
  "DWJC":"XX",
  "TJCS":"21122"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小晨毅哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值