Vue中的@blur/@focus事件解讀
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)文章
vue+el-menu實(shí)現(xiàn)菜單欄無限多層級分類
這篇文章主要為大家詳細(xì)介紹了vue+el-menu實(shí)現(xiàn)菜單欄無限多層級分類,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03vue 使用localstorage實(shí)現(xiàn)面包屑的操作
這篇文章主要介紹了vue 使用localstorage實(shí)現(xiàn)面包屑的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11vue-router中的hash和history兩種模式的區(qū)別
大家都知道vue-router有兩種模式,hash模式和history模式,這里來談?wù)剉ue-router中的hash和history兩種模式的區(qū)別。感興趣的朋友一起看看吧2018-07-07Vue $mount實(shí)戰(zhàn)之實(shí)現(xiàn)消息彈窗組件
這篇文章主要介紹了Vue $mount實(shí)現(xiàn)消息彈窗組件的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04vue動(dòng)態(tài)循環(huán)出的多個(gè)select出現(xiàn)過的變?yōu)閐isabled(實(shí)例代碼)
本文通過實(shí)例代碼給大家分享了vue動(dòng)態(tài)循環(huán)出的多個(gè)select出現(xiàn)過的變?yōu)閐isabled效果,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-11-11vue electron應(yīng)用調(diào)exe程序的實(shí)現(xiàn)步驟
這篇文章主要介紹了vue electron應(yīng)用調(diào)exe程序的實(shí)現(xiàn)步驟,用Python寫了一個(gè)本地服務(wù)編譯成exe程序,在electron程序啟動(dòng)后,自動(dòng)執(zhí)行exe程序,文中有詳細(xì)的代碼示例供大家參考,需要的朋友可以參考下2024-02-02vue?element?ui?Select選擇器如何設(shè)置默認(rèn)狀態(tài)
這篇文章主要介紹了vue?element?ui?Select選擇器如何設(shè)置默認(rèn)狀態(tài)問題,具有很好的參考價(jià)值,希望對大家有所幫助,2023-10-10vue中如何給el-table-column添加指定列的點(diǎn)擊事件
elementui中提供了點(diǎn)擊行處理事件,下面這篇文章主要給大家介紹了關(guān)于vue中如何給el-table-column添加指定列的點(diǎn)擊事件,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11