vue中使用vant中的图片预览组件出现图片在没有关闭改变路由图片不关闭解决方法

1.给图片点击查看创造全局变量 在data中定义  instance_before

lookImg() {
      this.instance_before = ImagePreview({
        images: [this.detailInfo.acupoint_img],//this.detailInfo.acupoint_img图片地址改成自//己的图片地址
      });
    },

2.在当前页面同过钩子函数在路由离开的时候,关闭预览的图片

 beforeRouteLeave(to, from, next) {
    this.instance_before.close();
    next();
  },

完美解决

猜你喜欢

转载自blog.csdn.net/wei80231996/article/details/111514036