亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue如何把字符串中的所有@內(nèi)容,替換成帶標(biāo)簽的

 更新時(shí)間:2023年10月09日 14:29:53   作者:妍崽崽@  
這篇文章主要介紹了vue如何把字符串中的所有@內(nèi)容,替換成帶標(biāo)簽的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

vue把字符串中的所有@內(nèi)容,替換成帶標(biāo)簽的

目前有個(gè)需求是,要把輸入框里面的@還有姓名高亮。

要求:

1、必須用 v-html ,帶標(biāo)簽的給他渲染

2、把字符串中的@全部查找出來,替換掉,注意要過濾已經(jīng)替換好的,不然就是無限循環(huán)了

實(shí)現(xiàn)方法:

// 消息展示中處理@樣式
const textPointTo = (content:any) => {
  let index = value.indexOf('@');
  while (index !== -1) {
    const endIndex = value.indexOf(' ', index);
    const replaceStr = value.substring(index, endIndex !== -1 ? endIndex : undefined);
    value = value.replace(replaceStr, `<span class='replyPointTo'>${replaceStr.split('@')[1]}</span>&nbsp;`);
    index = value.indexOf('@', index + 1);
 }
 return value.replace(/PointTo'>/g, "PointTo'>@")
};

字符串中各類字符標(biāo)簽過濾

1、替換字符串中的所有特殊字符(包含空格)

trimSpecial(string) {
 //替換字符串中的所有特殊字符(包含空格)
 if (string != '') {
 const pattern = /[`~!@#$^\-&nbsp*()=|{}':;',\\\[\]\.<>
\/?~!@#¥……&*()——|{}【】';:""'。,、?\s]/g
 string = string.replace(pattern, '')
 }
 return string
 }

2、過濾字符串中的img標(biāo)簽元素

 removeImg(v) {
 let data = v.replace(/<img.*>/gi, '')
 return data
 },

3、過濾轉(zhuǎn)義符、p標(biāo)簽

 removeP(v) {
 if (v != '') {
 v = v.replace(/ /gi, ' ')
 v = v.replace(/
/gi, '')
 v = v.replace(/</gi, '<')
 v = v.replace(/>/gi, '>')
 v = v.replace(/<br \/>/g, '')
 v = v.replace(/<\/?p[^>]*>/gi, '')
 }
 return v
 },

4、過濾掉html標(biāo)簽

 delHtmlTag(str) {
 let a = str
 var converter = document.createElement('DIV')
 converter.innerHTML = a
 var b = converter.innerText
 converter = null
 var c = b.replace(/[&\|\\\*^\-]/g, '')
 return c.replace(/\s*/g, '')
 },

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論