Vue中的@blur/@focus事件解讀
更新時間:2023年03月04日 14:28:12 作者:年輕即出發(fā)
這篇文章主要介紹了Vue中的@blur/@focus事件解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
Vue的@blur/@focus事件
@blur是當元素失去焦點時所觸發(fā)的事件@focus是元素獲取焦點時所觸發(fā)的事件
<template>
<div>
<!--
@blur 當元素失去焦點時觸發(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事件,改變選中時搜索框的背景色
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é)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue 使用localstorage實現(xiàn)面包屑的操作
這篇文章主要介紹了vue 使用localstorage實現(xiàn)面包屑的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
vue-router中的hash和history兩種模式的區(qū)別
大家都知道vue-router有兩種模式,hash模式和history模式,這里來談?wù)剉ue-router中的hash和history兩種模式的區(qū)別。感興趣的朋友一起看看吧2018-07-07
Vue $mount實戰(zhàn)之實現(xiàn)消息彈窗組件
這篇文章主要介紹了Vue $mount實現(xiàn)消息彈窗組件的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-04-04
vue動態(tài)循環(huán)出的多個select出現(xiàn)過的變?yōu)閐isabled(實例代碼)
本文通過實例代碼給大家分享了vue動態(tài)循環(huán)出的多個select出現(xiàn)過的變?yōu)閐isabled效果,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧2019-11-11
vue electron應(yīng)用調(diào)exe程序的實現(xiàn)步驟
這篇文章主要介紹了vue electron應(yīng)用調(diào)exe程序的實現(xiàn)步驟,用Python寫了一個本地服務(wù)編譯成exe程序,在electron程序啟動后,自動執(zhí)行exe程序,文中有詳細的代碼示例供大家參考,需要的朋友可以參考下2024-02-02
vue?element?ui?Select選擇器如何設(shè)置默認狀態(tài)
這篇文章主要介紹了vue?element?ui?Select選擇器如何設(shè)置默認狀態(tài)問題,具有很好的參考價值,希望對大家有所幫助,2023-10-10
vue中如何給el-table-column添加指定列的點擊事件
elementui中提供了點擊行處理事件,下面這篇文章主要給大家介紹了關(guān)于vue中如何給el-table-column添加指定列的點擊事件,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2022-11-11

