ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2021-09-24 16:33:17  阅读:250  来源: 互联网

标签:vue mc 配置文件 res item Vue import prototype 打包


在 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"
}

标签:vue,mc,配置文件,res,item,Vue,import,prototype,打包
来源: https://blog.csdn.net/weixin_43910866/article/details/120457770

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有