您好,欢迎来到榕意旅游网。
搜索
您的当前位置:首页资源合并与压缩的优化方法介绍

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

来源:榕意旅游网

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

要求

假定现在有路由/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>

Copyright © 2019- nryq.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务