当前位置:网站首页>Resolve the conflict between computed attribute and input blur event
Resolve the conflict between computed attribute and input blur event
2022-04-23 14:40:00 【Feather_ seventy-four】
background : The search box is reused on the home page and search page , The search content of the home page needs to be transferred to the search page and displayed in the search box . The mode of transmission is through this.$router.push
Add query
Field .
<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;
}
}
}
};
problem : stay input The data entered in will disappear when it loses focus
reason : When the page is initialized, it will execute get()
, No longer perform , Every time you enter data, you execute set()
. During the inspection, put the event in the listener blur
Get rid of , That would not have happened . But printed onblur
yes null
, So it can't be removed . So it's the problem of data return .
resolvent :
export default {
data() {
return {
sendSearchInfo: ''
};
},
methods: {
searchPaper(sendSearchInfo) {
this.$router.push({
path: '/search?',
query: {
info: sendSearchInfo
}
});
}
},
computed: {
searchInfo: {
get() {
// because get involves this.sendSearchInfo, So every time set Will trigger get
if (this.sendSearchInfo != '') {
return this.sendSearchInfo;
} else {
return this.$route.query.info;
}
},
set(val) {
this.sendSearchInfo = val;
}
}
}
};
版权声明
本文为[Feather_ seventy-four]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231435193327.html
边栏推荐
- Parameter stack pressing problem of C language in structure parameter transmission
- Detailed explanation of C language P2 selection branch statement
- I/O复用的高级应用:同时处理 TCP 和 UDP 服务
- 【NLP】HMM隐马尔可夫+维特比分词
- Achievements in science and Technology (21)
- 2-GO variable operation
- 基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
- 51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
- Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
- Unity_代码方式添加绑定按钮点击事件
猜你喜欢
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
Chapter 7 of JVM series -- bytecode execution engine
一个月把字节,腾讯,阿里都面了,写点面经总结……
电子秤称重系统设计,HX711压力传感器,51单片机(Proteus仿真、C程序、原理图、论文等全套资料)
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
线程同步、生命周期
自动化的艺术
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
数组模拟队列进阶版本——环形队列(真正意义上的排队)
[untitled]
随机推荐
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
压缩映射定理
vscode中文插件不生效问题解决
[detailed explanation of factory mode] factory method mode
外包幹了四年,廢了...
C语言知识点精细详解——数据类型和变量【1】——进位计数制
1 - first knowledge of go language
Master in minutes --- ternary operator (ternary operator)
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
Achievements in science and Technology (21)
Qt实战:云曦日历篇
2-Go变量操作
解决computed属性与input的blur事件冲突问题
1N5408-ASEMI整流二极管1N5408
科技的成就(二十一)
Detailed explanation of C language P2 selection branch statement
自动化的艺术
【NLP】HMM隐马尔可夫+维特比分词
redis的五种数据类型