当前位置:网站首页>解决computed属性与input的blur事件冲突问题
解决computed属性与input的blur事件冲突问题
2022-04-23 14:35:00 【Feather_74】
背景:搜索框在首页和搜索页复用,需要将首页的搜索内容传到搜索页并显示在搜索框内。传送方式是通过在this.$router.push方法中加query字段。
<template>
<div class="index-container">
<a-input-search class="input-shape" v-model="searchInfo" placeholder="Search" @search="searchPaper(sendSearchInfo)" size="large" />
</div>
</template>
export default {
data() {
return {
sendSearchInfo: ''
};
},
methods: {
searchPaper(sendSearchInfo) {
this.$router.push({
path: '/search?',
query: {
info: sendSearchInfo
}
});
}
},
computed: {
searchInfo: {
get() {
return this.$route.query.info;
},
set(val) {
this.sendSearchInfo = val;
}
}
}
};
问题:在input中输入的数据在失去焦点时会消失
原因:页面初始化的时候会执行get(),之后都不再执行,每次输入数据都会执行set()。在检查中把事件监听器中的blur去掉,就不会出现上述问题。但是打印了onblur是null,所以无法去掉。所以是数据返回的问题。
解决方法:
export default {
data() {
return {
sendSearchInfo: ''
};
},
methods: {
searchPaper(sendSearchInfo) {
this.$router.push({
path: '/search?',
query: {
info: sendSearchInfo
}
});
}
},
computed: {
searchInfo: {
get() {
// 因为get涉及到this.sendSearchInfo,所以每次set都会触发get
if (this.sendSearchInfo != '') {
return this.sendSearchInfo;
} else {
return this.$route.query.info;
}
},
set(val) {
this.sendSearchInfo = val;
}
}
}
};
版权声明
本文为[Feather_74]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44997147/article/details/124204803
边栏推荐
- C语言p2选择分支语句详解
- 四层和八层电梯控制系统Proteus仿真设计,51单片机,附仿真和Keil C代码
- Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
- 【NLP】HMM隐马尔可夫+维特比分词
- Some little records~
- 数组模拟队列进阶版本——环形队列(真正意义上的排队)
- MDS55-16-ASEMI整流模块MDS55-16
- 8.3 语言模型与数据集
- Detailed explanation of C language P2 selection branch statement
- OpenFaaS实战之四:模板操作(template)
猜你喜欢

基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等

TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别

Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data

线程同步、生命周期

四层和八层电梯控制系统Proteus仿真设计,51单片机,附仿真和Keil C代码

Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)

抑郁症治疗的进展

1分钟看懂执行流程,永久掌握for循环(附for循环案例)

全连接层的作用是什么?

关于UDP接收icmp端口不可达(port unreachable)
随机推荐
Upgrade of openssh and modification of version number
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
关于在vs中使用scanf不安全的问题
Qt界面优化:鼠标双击特效
LLVM - 生成 if-else 以及 PH
本以为能躺着进华为,结果陆续收到京东/滴滴/爱奇艺offer的我迷茫了
【NLP】HMM隐马尔可夫+维特比分词
asp.net使用MailMessage发送邮件的方法
【Servlet】Servlet 详解(使用+原理)
Use of ansible and common modules
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
JumpServer
OpenFaaS实战之四:模板操作(template)
TLS/SSL 协议详解 (28) TLS 1.0、TLS 1.1、TLS 1.2之间的区别
QT interface optimization: QT border removal and form rounding
阿里研发三面,面试官一套组合拳让我当场懵逼
Qt实战:云曦日历篇
详解TCP的三次握手
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
async void 导致程序崩溃