之前是向下面直接把json文件引入,但是打包以后,调取的json文件还是未改之前的内容。所以找到了别的办法。

import api from '../../static/serverConfig.json'

 然后找到了办法,引入了一个js

然后在要用的页面

import {$getJson} from './http'
const getH5StaticJson = data => {
  return $getJson('../../static/serverConfig.json', data)
}
getH5StaticJson({}).then(res => {
  console.log(res.data.API_URL)
})

贴代码。 

import axios from 'axios'
export const $getJson = function (method) {
  return new Promise((resolve, reject) => {
    axios({
      method: 'get',
      url: method,
      dataType: 'json',
      crossDomain: true,
      cache: false
    }).then(res => {
      resolve(res)
    }).catch(error => {
      reject(error)
    })
  })
}

借鉴原博主:https://www.cnblogs.com/yy136/p/9977864.html

Logo

前往低代码交流专区

更多推荐