在utils中新建一个js文件,文件名称随意
const geturl = 'http://IP地址:端口';
function handlerImg(imgStr) {
var tempArr = []
if (imgStr) {
if (imgStr.indexOf(',') !== -1) {
tempArr = imgStr.split(',').map(item => {
//如果里面没有http之类的加前缀
if (item.indexOf('http') === -1) {
item = geturl + item
}
return item
})
} else {
//如果里面没有http之类的加前缀
if (imgStr.indexOf('http') === -1) {
imgStr = geturl + imgStr
}
tempArr.push(imgStr)
}
}
return tempArr;
}
export default {
geturl, //访问后台图片地址
handlerImg //
}
在main.js中进行全局注册
import getPicture from '@/utils/getPicture'
Vue.prototype.$getPicture = getPicture;
在需要的地方进行引入
imgUp: this.$getPicture.geturl, 这里就是用的js里面的固定后台地址,如果地址发生改变,只需要修改js文件就可以