Vue项目 移动端禁止页面放大缩小

发布时间 2023-12-20 17:49:18作者: 维维WW

Vue项目 移动端禁止页面放大缩小(在安卓上可以实现禁止放大缩小,但是ios就不行)

// index.html 中添加 meta 标签
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover, user-scalable=0">

询才知道对于IOS10以上的苹果机子,上述方法是行不通的,可以尝试以下的方法

//在 src / app.vue 中 script 标签内添加代码
<script>
window.onload = function() {
    document.addEventListener('touchstart', function(e) {
      console.log("1",e.touches.length)
      if (e.touches.length > 1) {
        e.preventDefault()
      }
    })
    document.addEventListener('gesturestart', function(e) {
      console.log("2")
      e.preventDefault()
    })
  }
</script>

参考文章

https://blog.csdn.net/m0_67063430/article/details/127332534?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1-127332534-blog-128442012.235^v39^pc_relevant_anti_vip_base&spm=1001.2101.3001.4242.2&utm_relevant_index=4