vue打包可以配置接口ip并在docker中使用

在项目的static下新建文件config.json

{"BASE_API":"http://192.168.1.47:8080"}

在项目的main中读取这个文件并放到存储

import axios from 'axios'

axios.get('./../static/config.json').then((result) => {
  localStorage.setItem('BASE_API', result.data.BASE_API)
  // console.log(localStorage.getItem('BASE_API'))
}).catch((error) => { console.log(error) })

写一个py脚本到到static下modify_config.py

#!/usr/bin/python
import os
import sys
os.remove('config.json')
full_path = 'config.json'
file = open(full_path, 'w')
file.write('{"BASE_API":"http://'+sys.argv[1]+'/wgs/"}')
file.close()

在创建好docker容器后运行

docker exec -it DOCKER_ID /bin/bash -c 'cd /usr/local/nginx/html/static && python modify_config.py 192.168.1.1:8080'

 

你可能感兴趣的:(docker,vue,html)