各位大神:我是一个菜鸟,初学者。我要把富文本中的临时图片路径替换成图片上传成功后的网络路径,
upLoadArticle(e) {
var that = this
var htmlInfo = that.data.formData.content
var reg = /src=[\'\"]?([^\'\"]*)[\'\"]?/ig
var newHtmlInfo = htmlInfo.replace(reg,function($,$1){
var imageNumber = Date.parse(new Date()) + Math.round(Math.random() * 1000)
wx.cloud.uploadFile({
cloudPath:'news/'+ imageNumber + '.jpg',
filePath:$1,
success(res){
return res.fileID
}
})
})
console.log(newHtmlInfo)
},
请大神赐教!谢谢