Weui显示预览图片接口wx.previewImage展示相对路径图片

Weui显示预览图片接口wx.previewImag接口只支持全路径图片,相对路径图片,需要转为全路径,示例如下:

wx.ready(function() {
	//var urls = [ '../images/xxx.jpg'];
	var urls = [ getRootPath()+'/images/xxx.jpg'];
	wx.previewImage({
		current : urls[0],
		urls : urls
	});
});

function getRootPath() {
	var pathName = window.location.pathname.substring(1);
	var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
	return window.location.protocol + '//' + window.location.host + '/' + webName + '/';
}


打赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.