当前位置:网站首页>uni-app 微信小程序搜索关键字标红显示
uni-app 微信小程序搜索关键字标红显示
2022-07-26 23:07:00 【liuye066】

搜索关键字标红
修改字符串中部分字符的样式:
async getProductList() {
uni.showLoading({
title: '正在请求...'
})
let resPro = await getProducts({
keyword: this.keyword,
cate_id: this.currentCateId,
id: this.pro
})
//处理返回数据中的标签样式
if(Object.keys(resPro).length != 0) {
resPro.forEach((item,index)=>{
if(item.hasOwnProperty('withTags')) {
item.withTags.forEach((subItem,idx)=> {
if(subItem.product_tag.indexOf(this.keyword) != -1) {
subItem.product_tag = this.join(subItem.product_tag,this.keyword)
}
})
}
});
}
this.productList = resPro
console.log('getProductList',this.productList)
uni.hideLoading()
},
// 拼接
join(str,key){
var reg = new RegExp((`(${key})`), "gm");
var replace = '<span style="color:#FD463E;font-weight:bold;">$1</span>';
return str.replace(reg, replace);
},显示:
<u-tag v-for="(vo,key) in item.withTags" :key="key" :text="vo.product_tag" :keyName="keyword"
color="#414141" bgColor="#eaebeb" borderColor="#eaebeb" shape="circle" size="mini" type="warning">
</u-tag>u-tag.vue
<!-- <text
class="u-tag__text"
:style="[textColor]"
:class="[`u-tag__text--${type}`, plain && `u-tag__text--${type}--plain`, `u-tag__text--${size}`]"
>{
{ text}} </text> -->
<rich-text
:nodes="text"
class="u-tag__text"
:style="[textColor]"
:class="[`u-tag__text--${type}`, plain && `u-tag__text--${type}--plain`, `u-tag__text--${size}`]"
> </rich-text>在原来的<text>中无法正常显示。会把标签和样式都显示出来或不显示内容。在<rich-text>中的nodes中可以正常显示
边栏推荐
猜你喜欢

RIP路由信息协议-拓扑实验

HCIP-第六天-OSPF静态大实验

记录第N次SQL异常

离开页面的提示

What is the principle of synchronized lock escalation in multithreading?
![[do you know cache - fully understand cache]](/img/65/df29f6f1ff6d0d119da4a3971db0fc.png)
[do you know cache - fully understand cache]

Is it useful to lie down with your eyes closed when you can't sleep?

Static routing experiment configuration

Record the star user of handsomeblog

OSPF路由信息协议-拓扑实验
随机推荐
TCP three handshakes and four disconnects
Array methods and loops in JS
Qt中文乱码常量换行符终极解决方案
(CF1691D) Max GEQ Sum
C language - value range of data type and basic data type
Lvs+keepalived project practice
Writing a pacesetter frequently -- yunxiaojing
Hcip day 5 OSPF extended configuration experiment
[draw sherpinski triangle in C language]
Error handling in golang
30岁被裁,我想明白的几件事....
C language - array, string handler, strlen, strcpy and strncpy, strcat and strncat, StrCmp and strncmp
C language -- while statement, dowhile statement, for loop and loop structure, break statement and continue statement
SQL优化的N种方法
C language -- nesting of relational and logical operators, if statements, switch statements, and branch structures
The latest JD SMS login + silly girl robot nanny level deployment tutorial (July 24, 2022)
How does the whole network display IP ownership?
【降维打击,带你深度学习CPU(上)】
勤写标兵——云小井
Golang implements TCP chat room