Vue中失去焦點(diǎn)時(shí)所觸發(fā)的事件問(wèn)題
Vue失去焦點(diǎn)時(shí)所觸發(fā)的事件
1-html、失去焦點(diǎn)
<input type="text" onBlur="txtblur()"> <script> ? ? function txtblur(event){ //當(dāng)前元素失去焦點(diǎn) ? ? ? ? console.log(123); ? ? } </script>
2-vue2.0、失去焦點(diǎn)
@input 一般用于監(jiān)聽(tīng)事件,只要輸入的值變化了就會(huì)觸發(fā)input
<input? ? ? ? ?:type="type"? ? ? ? ?:value="value"? ? ? ? ?:placeholder="placeholder"? ? ? ? ?:name="name"? ? ? ? ?@input="$emit('input',$event.target.value)" ? ? ? ?/>
@click 事件觸發(fā)事件
<input type="text" @click="clickFn">
@blur 是什么?
@blur 是當(dāng)元素失去焦點(diǎn)時(shí)所觸發(fā)的事件
使用
<template> ? <div> ? ? <input type="text" placeholder="請(qǐng)輸入內(nèi)容" @blur="blur"/> ? </div> </template> <script> ? ? export default { ? ? ? name: "@blur_61", ? ? ? methods:{ ? ? ? ? blur(){ ? ? ? ? ? console.log("blur事件被執(zhí)行") ? ? ? ? } ? ? ? } ? ? } </script> <style scoped> </style>
3-vue3.0、失去焦點(diǎn)
結(jié)構(gòu)
<el-input ? ? ? ? ? v-model="inputValue" ? ? ? ? ? v-bind="$attrs" ? ? ? ? ? @blur="handleBlur" ? ? ? ? ? @input="handleInput" ? ? ? ? ? class="custom-input" ? ? ? ? ? > </el-input>
方法
const handleBlur = () => {} const handleInput = ?(v) => {} return { ? ? ...toRefs(state), ? ? handleBlur, ? ? handleInput };
vue div獲得焦點(diǎn)和失去焦點(diǎn)
<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() //獲得焦點(diǎn) 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; /*移動(dòng)時(shí)的過(guò)度效果*/ transition: left 500ms ease; color: #fff; } } @media screen and (max-width: 1200px) { /*隱藏在左邊*/ .aside { position: fixed; /*相對(duì)于窗口固定定位*/ top: 0; left: -200px; /*隱藏在左邊*/ width: 200px; height: 100vh; margin: 0; padding: 0; background-color: #23303E; z-index: 100; /*移動(dòng)時(shí)的過(guò)度效果*/ transition: left 500ms ease; /*padding: 36px;*/ color: #fff; } } /*可以滾動(dòng),但隱藏滾動(dòng)條*/ .aside::-webkit-scrollbar { display: none; }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解在vue使用weixin-js-sdk常見(jiàn)使用方法
這篇文章主要介紹了 詳解在vue使用weixin-js-sdk常見(jiàn)使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05詳解Vue開(kāi)發(fā)微信H5微信分享簽名失敗問(wèn)題解決方案
這篇文章主要介紹了詳解Vue開(kāi)發(fā)微信H5微信分享簽名失敗問(wèn)題解決方案,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08Vue實(shí)現(xiàn)Echarts圖表寬高自適應(yīng)的實(shí)踐
本文主要介紹了Vue實(shí)現(xiàn)Echarts圖表寬高自適應(yīng)的實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11Vue中Axios中取消請(qǐng)求及阻止重復(fù)請(qǐng)求的方法
為了防止用戶在網(wǎng)絡(luò)不好或者其他情況下短時(shí)間內(nèi)重復(fù)進(jìn)行接口請(qǐng)求,重復(fù)發(fā)送多次請(qǐng)求,本文主要介紹了Vue中Axios中取消請(qǐng)求及阻止重復(fù)請(qǐng)求的方法,感興趣的可以了解一下2022-02-02vue3+vite自定義封裝vue組件發(fā)布到npm包的全過(guò)程
當(dāng)市面上主流的組件庫(kù)不能滿足我們業(yè)務(wù)需求的時(shí)候,那么我們就有必要開(kāi)發(fā)一套屬于自己團(tuán)隊(duì)的組件庫(kù),下面這篇文章主要給大家介紹了關(guān)于vue3+vite自定義封裝vue組件發(fā)布到npm包的相關(guān)資料,需要的朋友可以參考下2022-09-09