微信的JS
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
预览图片方法
new Vue({
el: '.m-xc-news',
data: function () {
return {
}
},
methods:{
funcReadImgInfo() {
let imgs = [];
//获取图文中全部的img标签对象
let imgObj = document.getElementsByTagName('img');
let l = imgObj.length;
// 遍历获取url
for (let i = 0; i < l; i++) {
imgs.push(imgObj[i].src);
//以下调用微信内置图片浏览组建
imgObj[i].onclick = function () {
let nowImgurl = this.src;
//获取当前点击图片url 切记 url必须是 http
WeixinJSBridge.invoke("imagePreview", {
"urls": imgs,
"current": nowImgurl
})
}
}
}
},
mounted: function () {
var _this = this;
var ua = navigator.userAgent.toLowerCase();
// 判断是否是微信浏览器
var isWeixin = ua.indexOf('micromessenger') != -1;
if (isWeixin) {
setTimeout(function(){
_this.funcReadImgInfo();
},500)
}
}
});
原生js加载
window.οnlοad=function(){
var _this = this;
_this.funcReadImgInfo();
}
亲测好用,采用vue框架