如何将Vue中div的focus和blur事件改写为长尾词?

2026-04-01 13:321阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计496个文字,预计阅读时间需要2分钟。

如何将Vue中div的focus和blur事件改写为长尾词?

目录 + Vue + div + focus + blur 焦点事件 + Vue + div + 获取焦点和失去焦点 + Vue + div + focus + blur 焦点事件 + onfocus + 获取焦点事件与 onblur 失去焦点事件 + 本身是 input 类型的 + input 类如点击后加载的文字需做延迟

目录
  • vue div focus blur焦点事件
  • vue div 获得焦点和失去焦点

vue div focus blur焦点事件

  • onfocus获取焦点事件与onblur失去焦点事件本身是input类用的
  • input类如果是点击后才加载的话需要做个延时器,否则会报错

setTimeout(()=>{     this.$refs.aside.focus() },100)

div想支持则需要加上tabindex="0"属性//0或者以上

但是在vue环境中,加上这个也不支持,而移动端无法使用鼠标事件

<div tabindex="0" hidefocus="true" ref="aside" class="aside" @click="dialaing()" @blur='()=>{dialaingIsShow =false}'>     <div v-show="dialaingIsShow" class="dialaing">dsadasd</div> </div>

dialaing(){        this.$refs.aside.focus()        this.dialaingIsShow = true },

就可以了

如何将Vue中div的focus和blur事件改写为长尾词?

vue div 获得焦点和失去焦点

<div tabindex="0" @blur="aside1_hide()" ref="aside1" class="aside" style="width: 200px; overflow: scroll;"> <!-- background-color="#23303E" transparent --> <el-menu background-color="#23303E" text-color="#fff" active-text-color="#fff"> ... </el-menu> </div>

left_click: function() { if (!this.left_show) { this.$refs.aside1.style.left = "0" this.$refs.aside1.focus() //获得焦点 this.left_show = true } else { this.aside1_hide() } }, aside1_hide:function () { this.$refs.aside1.style.left = "-200px" this.left_show = false },

@media screen and (min-width: 1200px) { .aside { position: static; width: 200px; height: 100vh; margin: 0; padding: 0; background-color: #23303E; z-index: 100; /*移动时的过度效果*/ transition: left 500ms ease; color: #fff; } } @media screen and (max-width: 1200px) { /*隐藏在左边*/ .aside { position: fixed; /*相对于窗口固定定位*/ top: 0; left: -200px; /*隐藏在左边*/ width: 200px; height: 100vh; margin: 0; padding: 0; background-color: #23303E; z-index: 100; /*移动时的过度效果*/ transition: left 500ms ease; /*padding: 36px;*/ color: #fff; } } /*可以滚动,但隐藏滚动条*/ .aside::-webkit-scrollbar { display: none; }

以上为个人经验,希望能给大家一个参考,也希望大家多多支持易盾网络。

本文共计496个文字,预计阅读时间需要2分钟。

如何将Vue中div的focus和blur事件改写为长尾词?

目录 + Vue + div + focus + blur 焦点事件 + Vue + div + 获取焦点和失去焦点 + Vue + div + focus + blur 焦点事件 + onfocus + 获取焦点事件与 onblur 失去焦点事件 + 本身是 input 类型的 + input 类如点击后加载的文字需做延迟

目录
  • vue div focus blur焦点事件
  • vue div 获得焦点和失去焦点

vue div focus blur焦点事件

  • onfocus获取焦点事件与onblur失去焦点事件本身是input类用的
  • input类如果是点击后才加载的话需要做个延时器,否则会报错

setTimeout(()=>{     this.$refs.aside.focus() },100)

div想支持则需要加上tabindex="0"属性//0或者以上

但是在vue环境中,加上这个也不支持,而移动端无法使用鼠标事件

<div tabindex="0" hidefocus="true" ref="aside" class="aside" @click="dialaing()" @blur='()=>{dialaingIsShow =false}'>     <div v-show="dialaingIsShow" class="dialaing">dsadasd</div> </div>

dialaing(){        this.$refs.aside.focus()        this.dialaingIsShow = true },

就可以了

如何将Vue中div的focus和blur事件改写为长尾词?

vue div 获得焦点和失去焦点

<div tabindex="0" @blur="aside1_hide()" ref="aside1" class="aside" style="width: 200px; overflow: scroll;"> <!-- background-color="#23303E" transparent --> <el-menu background-color="#23303E" text-color="#fff" active-text-color="#fff"> ... </el-menu> </div>

left_click: function() { if (!this.left_show) { this.$refs.aside1.style.left = "0" this.$refs.aside1.focus() //获得焦点 this.left_show = true } else { this.aside1_hide() } }, aside1_hide:function () { this.$refs.aside1.style.left = "-200px" this.left_show = false },

@media screen and (min-width: 1200px) { .aside { position: static; width: 200px; height: 100vh; margin: 0; padding: 0; background-color: #23303E; z-index: 100; /*移动时的过度效果*/ transition: left 500ms ease; color: #fff; } } @media screen and (max-width: 1200px) { /*隐藏在左边*/ .aside { position: fixed; /*相对于窗口固定定位*/ top: 0; left: -200px; /*隐藏在左边*/ width: 200px; height: 100vh; margin: 0; padding: 0; background-color: #23303E; z-index: 100; /*移动时的过度效果*/ transition: left 500ms ease; /*padding: 36px;*/ color: #fff; } } /*可以滚动,但隐藏滚动条*/ .aside::-webkit-scrollbar { display: none; }

以上为个人经验,希望能给大家一个参考,也希望大家多多支持易盾网络。