首页  >  文章  >  web前端  >  资源合并与压缩的优化方法介绍

资源合并与压缩的优化方法介绍

不言
不言转载
2019-03-15 14:17:312421浏览

本篇文章给大家带来的内容是关于资源合并与压缩的优化方法介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

要求

假定现在有路由/news,/login监听键盘事件,只允许在/news页面内有效不管后面跳到哪个页面,都不会触发对应的键盘事件,只能在/news里才触发

问题

没有进入/news之前,按键盘上的键,不会触发事件,进过/news后,不管有没有按键盘上的键,再跳到别的页面,按键盘上的键,都会触发事件

代码

srcviewsnews.vue

<template>
  <div>
    news
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: true, //底部图片列表显示隐藏
      name: "aa"
    };
  },
  methods: {
    keyLeft() {
      alert(this.name);
    },
    keyUp() {
      alert("向上方向键");
    },
    keyRight() {
      alert("向右方向键");
    },
    keyDown() {
      alert("向下方向键");
    },
    keys() {
      var that = this;
      document.onkeydown = function(e) {
        let key = window.event.keyCode;
        if (key == 37) {
          that.keyLeft();
        } else if (key == 38) {
          that.keyUp();
          return false; //有上下滚动条的时候,不向上滚动
        } else if (key == 39) {
          that.keyRight();
        } else if (key == 40) {
          that.keyDown();
          return false; //有上下滚动条的时候,不向上滚动
        }
      };
    }
  },
  created() {
    if (this.flag == true && this.$route.path == "/news") {
      this.keys();
    }
  },
  mounted() {}
};
</script>

以上是资源合并与压缩的优化方法介绍的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:segmentfault.com。如有侵权,请联系admin@php.cn删除