[Ruimo.com] html WeChat built-in browser, click on the picture to enlarge, pinch to zoom, with source code (available for self-test)

Quote WeChat's JS

<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
/*调用微信预览图片的方法*/
        funcReadImgInfo() {
            let imgs = [];
            //获取图文中全部的img标签对象
            let imgObj = document.getElementsByClassName('image_box');
            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
                    })
                }
            }
        },

The native js page is loaded and called:

window.οnlοad=function(){
    var _this = this;
    _this.funcReadImgInfo();
}

After the vue page is loaded, call:

// 异步数据请求完成以后
setTimeout(function(){
    var _this = this;
    _this.funcReadImgInfo();
},500)

Guess you like

Origin blog.csdn.net/rrmod/article/details/128923772