1. 去掉url中的域名的方法
url = url.replace(/^http:\/\/[^/]+/, "");
2. 过滤html标签中的图片路径
var imgArr = response.data.detail.detail_content;
// console.log("商品详情",response.data.detail.detail_content);
var imgReg = /<img.*?(?:>|\/>)/gi;
var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
var arr = imgArr.match(imgReg);
let detailArr = [];
for (var i=0; i<arr.length; i++) {
detailArr.push(arr[i].match(srcReg)[1]);
// console.log(arr[i].match(srcReg)[1]);
}
_this.detail_content = detailArr.join(","); //数组转字符串
if(arr.length == _this.detailList.length){
}else{
detailArr.forEach(item=>{
_this.detailList.push(_this.$global.imgUrl+item);
})
}
3. 数组转字符串
Arr.join(",");
4. 字符串转数组
string.split(",");
5. 移除数组中的某一项
arr.splice(index, 1);