这是我的代码:
var thisImageName = thisRow["imagename"];
var thisImagePath = path.relative("./public", __dirname + "/public/uploads/" + thisImageName + ".jpg");
console.log(thisImagePath); // returns __dirname\public\uploads\
img.src = thisImagePath.split(path.sep).join("/");
要获得适当的图像路径,我必须按路径分隔符拆分,然后用适当的斜杠加入数组。有谁知道这样做更有效的方法?