Vue中失去焦點(diǎn)時(shí)所觸發(fā)的事件問題
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)聽事件,只要輸入的值變化了就會(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í)的過度效果*/
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í)的過度效果*/
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實(shí)現(xiàn)Echarts圖表寬高自適應(yīng)的實(shí)踐
本文主要介紹了Vue實(shí)現(xiàn)Echarts圖表寬高自適應(yīng)的實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
Vue中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-02
vue3+vite自定義封裝vue組件發(fā)布到npm包的全過程
當(dāng)市面上主流的組件庫(kù)不能滿足我們業(yè)務(wù)需求的時(shí)候,那么我們就有必要開發(fā)一套屬于自己團(tuán)隊(duì)的組件庫(kù),下面這篇文章主要給大家介紹了關(guān)于vue3+vite自定義封裝vue組件發(fā)布到npm包的相關(guān)資料,需要的朋友可以參考下2022-09-09

