newUrl.js
//引入接口中的域名
import baseUrl from './config.js';
function imageUrl(url){
let str = RegExp('http');
let newUrl;
//通过三元运算符进行判断该图片是否含有http域名,没有就拼接上去
str.test(url) ? newUrl = url : newUrl = baseUrl.url + url;
return newUrl
}
module.exports = imageUrl;
引入newUrl.js
import imageUrl from '../../../utils/newUrl.js';
//直接需要判断调用,url为图片字段
imageUrl(url)