Home > Web Front-end > JS Tutorial > Loading and execution of css and js (with code)

Loading and execution of css and js (with code)

不言
Release: 2019-03-15 14:05:13
forward
2017 people have browsed it

The content this article brings to you is about the loading and execution of css and js (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Requirements

Assume that there is a route /news, /login listens for keyboard events, and is only allowed to be valid within the /news page, no matter which page it jumps to later, it will not Triggering the corresponding keyboard event can only be triggered in /news

Problem

Before entering /news, pressing the keys on the keyboard will not trigger the event. After entering /news, regardless of whether you press the keys on the keyboard or not, if you jump to another page and press the keys on the keyboard, the event will be triggered

Code

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>
Copy after login

The above is the detailed content of Loading and execution of css and js (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template