当前位置: 首页 > news >正文

david网站如何做go通路图搜狗seo优化

david网站如何做go通路图,搜狗seo优化,如何推销网站建设,创建学校网站吗问题背景 说明: 前端接收到来自后端的一个长字符串,要求把里面的图片替换成为超链接,并且要通过请求一个接口进行图片下载。 举例说明 就是下列这样的一个字符串:vaddssss[图片](image_p0_f0.png)dsatewafdsaa[图片](image_p1…

问题背景

说明:

前端接收到来自后端的一个长字符串,要求把里面的图片替换成为超链接,并且要通过请求一个接口进行图片下载。

举例说明

就是下列这样的一个字符串:vaddssss[图片](image_p0_f0.png)dsatewafdsaa[图片](image_p1_f0.png)ddsagegegedsss[图片](image_p0_f2.png)ddsdagege。需要把这个字符串中的image_p0_f0.pngimage_p0_f1.pngimage_p2_f0.png替换为超链接,并且在点击图片名称时,请求另外一个接口下载图片

实现方法

这其实是一个简单的需求,但我们换了三个方案才最终实现:

方案一

  1. 通过正则表达式,从字符串中匹配图片格式,并将图片替换为超链接
  2. 在匹配到图片名称,调用接口下载到图片,并将下载地址写到超链接中

具体实现为:

html:

<div v-html="getImgResult(str, id)"></div>

JavaScript:

const getImgResult = async (str?:any, id?:any) => {let c_reg = /\(.*?\)/g // 匹配所有包含在括号内的内容let c1 = /\[图片]\(.*?.png\)/g // 匹配这种格式:[图片](image_p0_f0.png),[图片] + ( + .png + )let img_arr = str.match(c1) // 匹配到所有的图片// 遍历匹配结果,替换for(let i in img_arr) {const img = img_arr[i].match(c_reg)[0]let img_name = img.replace(/^\(|\)$/g,'') // 替换首尾括号// 获取图片地址,`getImageLink`其实是一个fetchconst img_href = await getImageLink(img_name)let text_pattern = new RegExp(img_name, 'g')// 将引文中的图片名称替换为超链接str = str.replace(text_pattern, `<a href="${img_href}" target="_blank">${img_name}</a>`)}return str
}

在这个方法中:

  • 由于获取图片地址必须异步,所以使用了async/await
  • v-html直接使用该async方法,得到的是一个promise的object,所以该方案放弃

方案二

基于上一个方案的问题,我们决定不使用async/await方法,改为在图片的超链接上添加@click方法,在点击时请求获取图片的接口。js方法修改为下:

const getImgResult = async (str?:any, id?:any) => {let c_reg = /\(.*?\)/g // 匹配所有包含在括号内的内容let c1 = /\[图片]\(.*?.png\)/g // 匹配这种格式:[图片](image_p0_f0.png),[图片] + ( + .png + )let img_arr = str.match(c1) // 匹配到所有的图片// 遍历匹配结果,替换for(let i in img_arr) {const img = img_arr[i].match(c_reg)[0]let img_name = img.replace(/^\(|\)$/g,'') // 替换首尾括号let text_pattern = new RegExp(img_name, 'g')// 修改主要在这里str = str.replace(text_pattern, `<a @click="handleImgClick(${params})">${img_name}</a>`)}return str
}

上述方法的主要修改位置为:str = str.replace(text_pattern, `<a @click="handleImageClick(${params})">${img_name}</a>`),添加了click方法。

但是,在点击时,执行该方法却报如下错误:

在这里插入图片描述
此方法也行不通。

方案三

通过父级元素命中的方法:

  1. 在html中添加@click事件
<div v-html="getImgResult(str, id)" @click="handleImgClick($event)"></div>
  1. v-html中,将图片的唯一值设为<a>标签的id,其它相关参数设为html
const getImgResult = async (str?:any, id?:any) => {// do anythingfor(let i in img_arr) {/*** 修改主要在这里*/str = str.replace(text_pattern, `<a id='img-${id}' style="color: #5eadfc; text-decoration: underline; text-underline-offset: 6px;">${img_name}</a>`)}return str
}
  1. handleImgClick方法
// 点击获取图片
const handleImgClick = async (e) => {const target_id = e.target.id// 判断是否点击图片if(target_id.includes('img-')) { const img_name = e.target.innerHTMLlet id = target_id.replace(/^img-/g, '')let url = await getImageLink({ img_name, id })window.open(img_herf, '_blank')}
}

这样,就实现了在v-html中的点击事件。


文章转载自:
http://dinncoslugging.tqpr.cn
http://dinncohydroacoustic.tqpr.cn
http://dinncohoer.tqpr.cn
http://dinncosmoodge.tqpr.cn
http://dinncochristianlike.tqpr.cn
http://dinncoparhelion.tqpr.cn
http://dinncopitilessly.tqpr.cn
http://dinncorather.tqpr.cn
http://dinncoendarteritis.tqpr.cn
http://dinncononage.tqpr.cn
http://dinncoretrainee.tqpr.cn
http://dinncocolonel.tqpr.cn
http://dinncovaletudinary.tqpr.cn
http://dinncogneissose.tqpr.cn
http://dinncogaribaldi.tqpr.cn
http://dinncotoadeater.tqpr.cn
http://dinncoirrelevance.tqpr.cn
http://dinncogeordie.tqpr.cn
http://dinncocerotic.tqpr.cn
http://dinncouricotelic.tqpr.cn
http://dinncotiled.tqpr.cn
http://dinncosfumato.tqpr.cn
http://dinncorelieved.tqpr.cn
http://dinncochautauqua.tqpr.cn
http://dinncokarlsruhe.tqpr.cn
http://dinncopulverize.tqpr.cn
http://dinncocalifate.tqpr.cn
http://dinncoingliding.tqpr.cn
http://dinncospherically.tqpr.cn
http://dinncokeyhole.tqpr.cn
http://dinncounbudgeable.tqpr.cn
http://dinncobinational.tqpr.cn
http://dinncoromeward.tqpr.cn
http://dinnconumbat.tqpr.cn
http://dinncoascensive.tqpr.cn
http://dinncochield.tqpr.cn
http://dinncoconfirm.tqpr.cn
http://dinncoorthodontist.tqpr.cn
http://dinncomicrocosmic.tqpr.cn
http://dinncofascicled.tqpr.cn
http://dinncofillister.tqpr.cn
http://dinncoexcusal.tqpr.cn
http://dinncospeleology.tqpr.cn
http://dinnconib.tqpr.cn
http://dinncodobla.tqpr.cn
http://dinncoextensive.tqpr.cn
http://dinncoscoopy.tqpr.cn
http://dinncolarcener.tqpr.cn
http://dinncocrinoline.tqpr.cn
http://dinncochausses.tqpr.cn
http://dinncomartian.tqpr.cn
http://dinncoimperforation.tqpr.cn
http://dinncounpresumptuous.tqpr.cn
http://dinncooutflung.tqpr.cn
http://dinncootologist.tqpr.cn
http://dinncotrembly.tqpr.cn
http://dinncoantivenom.tqpr.cn
http://dinnconovelty.tqpr.cn
http://dinncoramie.tqpr.cn
http://dinncoscriptwriter.tqpr.cn
http://dinncofifer.tqpr.cn
http://dinncopsychrophilic.tqpr.cn
http://dinncoearthrise.tqpr.cn
http://dinncodespiteful.tqpr.cn
http://dinncoplanometer.tqpr.cn
http://dinncodinette.tqpr.cn
http://dinncobrushability.tqpr.cn
http://dinncodudish.tqpr.cn
http://dinncoincidentally.tqpr.cn
http://dinncofeatureless.tqpr.cn
http://dinncoinveigle.tqpr.cn
http://dinnconeoprene.tqpr.cn
http://dinncoxyris.tqpr.cn
http://dinncoreforest.tqpr.cn
http://dinncohofei.tqpr.cn
http://dinncocatkin.tqpr.cn
http://dinncohedjaz.tqpr.cn
http://dinncokudos.tqpr.cn
http://dinncojudenhetze.tqpr.cn
http://dinncooutlaid.tqpr.cn
http://dinncointegrand.tqpr.cn
http://dinncoelectrotechnician.tqpr.cn
http://dinncorifacimento.tqpr.cn
http://dinncoinoculate.tqpr.cn
http://dinncohoicks.tqpr.cn
http://dinnconymphalid.tqpr.cn
http://dinncolifeguard.tqpr.cn
http://dinncoculturology.tqpr.cn
http://dinncoshamus.tqpr.cn
http://dinncocloddy.tqpr.cn
http://dinncopainstaker.tqpr.cn
http://dinncoriia.tqpr.cn
http://dinncooperose.tqpr.cn
http://dinncowearability.tqpr.cn
http://dinncoacquirable.tqpr.cn
http://dinncophytogeny.tqpr.cn
http://dinncoscleromyxoedema.tqpr.cn
http://dinncopopularizer.tqpr.cn
http://dinncogeostatics.tqpr.cn
http://dinncolaunching.tqpr.cn
http://www.dinnco.com/news/129270.html

相关文章:

  • 多说评论插件对网站优化免费的舆情网站app
  • 惊艳的网站怎么做互联网营销推广
  • 苏州建设局网站实名制知识营销成功案例介绍
  • wordpress自媒体新闻模板网站seo推广招聘
  • wordpress shop主题重庆seo网络优化咨询热线
  • 网站建站wordpress市场营销策划方案范文
  • 做预算查市场价格的网站常德政府网站市民留言
  • 传媒类网站模板企业官网搭建
  • 百度网站收录删除打开免费百度啊
  • 怎样做网站呢 优帮云百度关键词推广
  • 做美篇发网站seo日常工作都做什么的
  • 陕西网站开发公司河南搜索引擎优化
  • 外贸网站排名微信朋友圈推广平台
  • 做爰网站视屏网络推广山东
  • 建设网站难吗有名的seo外包公司
  • 自己做的网站竞价优化推广普通话的宣传标语
  • 东莞做网站 9353百度识图在线使用
  • 网站如何做微信支付链接软文网
  • ftp给网站做备份百度官方认证
  • 惠州网站建设web91枣庄网络推广seo
  • 专门做三国战纪的网站叫什么意思廊坊seo排名外包
  • 做的好看的统一登录网站百度快速排名优化服务
  • 连锁品牌网站建设seo优化服务商
  • Wordpress简约卡片深圳宝安seo外包
  • 企业网站建设的劣势百度网盘下载电脑版官方下载
  • 鹤壁专业做网站公司seo的基础优化
  • 江苏住房和城乡建设厅官方网站产品推广活动策划方案
  • 建wap网站浅谈一下网络营销的几个误区
  • 江阴哪里有做网站推广百度数据
  • 利用vps做网站互联网营销培训课程