亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue中的@blur/@focus事件解讀

 更新時(shí)間:2023年03月04日 14:28:12   作者:年輕即出發(fā)  
這篇文章主要介紹了Vue中的@blur/@focus事件解讀,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Vue的@blur/@focus事件

  • @blur 是當(dāng)元素失去焦點(diǎn)時(shí)所觸發(fā)的事件
  • @focus是元素獲取焦點(diǎn)時(shí)所觸發(fā)的事件
 
<template>
  <div>
    <!--
    @blur 當(dāng)元素失去焦點(diǎn)時(shí)觸發(fā)blur事件
    -->
    <div>
      <input type="text" placeholder="請輸入內(nèi)容" @blur="blurText"/>
    </div>
 
  </div>
</template>
 
<script>
    export default {
      name: "commitText",
      methods:{
        blurText(){
          console.log("blur事件被執(zhí)行了")
        }
      }
    }
</script>
 
<style scoped>
 
</style>

focus和blur事件,改變選中時(shí)搜索框的背景色

template

<div class="search-box" ref="searchBoxOfChatRoom">
?? ?<i class="fa fa-search" aria-hidden="true"></i>
?? ?<input
?? ??? ?ref="searchOfChatRoom"
?? ??? ?class="chatroom-search"
?? ??? ?type="search"
?? ??? ?placeholder="搜索群成員"
?? ??? ?@focus="changBackground(1)"
?? ??? ?@blur="changBackground(2)"
?? ?>
</div>

js

changBackground (flag) {

? switch (flag) {
? ? case 1:
? ? ? console.log('獲取焦距')
? ? ? this.$refs.searchBoxOfChatRoom.style.background = 'white'
? ? ? this.$refs.searchOfChatRoom.style.background = 'white'
? ? ? break
? ? case 2:
? ? ? console.log('失去焦距')
? ? ? this.$refs.searchBoxOfChatRoom.style.background = '#dadada'
? ? ? this.$refs.searchOfChatRoom.style.background = '#dadada'
? ? ? break
? ? default:
? ? ? break
? }
}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論