V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
CareiOS
V2EX  ›  Vue.js

Vue 如何不让背景滚动?

  •  
  •   CareiOS · 2017-04-09 11:08:23 +08:00 · 4967 次点击
    这是一个创建于 2571 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有一个 class 为 layer 的 div, 使用了 v-on:touchmove.prevent ,应该阻止了背景滚动,可是背景列表还是会滚动,求解,代码如下。

    <template>
      <div id="app">
        <!--<my-button @click.native="buttonClick"></my-button>-->
        <img src="./assets/logo.png">
        <!--<router-view></router-view>-->
        <ul>
          <li v-for="item in list">
            <h1>{{ item }}</h1>
          </li>
        </ul>
        <div class="layer" v-on:touchmove.prevent></div>
      </div>
    </template>
    
    <script>
    // import myButton from '@/components/MyButton.vue'
    export default {
      // components: {
      //   myButton
      // },
      data () {
        return {
          list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        }
      },
      methods: {
        buttonClick () {
          alert('原生点击')
        }
      },
      name: 'app'
    }
    </script>
    
    <style>
    body, html {width: 100%; height: 100%}
    h1{margin-top:10rem;}
    .layer{width:100%;height: 100%;position: fixed;top:0;left:0;z-index: 99;background:rgba(0, 0, 0, 0.5)}
    #app {
      font-family: 'Avenir', Helvetica, Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      text-align: center;
      color: #2c3e50;
      margin-top: 60px;
    }
    </style>
    
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5292 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 01:25 · PVG 09:25 · LAX 18:25 · JFK 21:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.