<template>
  <div>
    <input v-focus />
    <button @click="test">测试</button>
    <div id="div1" tabindex="1">tabindex</div>
    <div style="font-size:20px" v-html="html"></div>
  </div>

</template>
<script>
  export default {
    created() {},
    mounted() {
      let _this = this
      document.addEventListener('keydown', function (event) {
        let str = 'code=' + event.code + '; key=' + event.key + '; keyCode=' + event.keyCode + '; type=' + event
          .type +
          '; which=' + event.which
        _this.html += str + '<br/>'
      })
      setTimeout(() => {
        document.getElementById('div1').focus()
      }, 1000);
    },
    data() {
      return {
        html: ''
      }
    },
    methods: {
        test(){
            this.html+='测试'+ '<br/>'
        }
    },
    computed: {},
    components: {},
    watch: {},
    props: {},
    directives: {
      focus: {
        inserted(el) {
          el.focus()
        }
      }
    }
  }

</script>
<style lang="less" scoped>
</style>
