[英]Replace <a> link with <nuxt-link> in string variable
I retrieve content from a CMS system (WordPress).我从 CMS 系统 (WordPress) 中检索内容。 In the "page.content" variable, links are outputted like so:
<a href="#">
.在“page.content”变量中,链接输出如下:
<a href="#">
。 How can I replace this content with: <nuxt-link to="#">
on the client side?如何在客户端用
<nuxt-link to="#">
替换此内容?
The question has been asked before, but no real answers: https://github.com/nuxt/nuxt.js/issues/2912 - despite this must be a pretty regular usecase.之前已经问过这个问题,但没有真正的答案: https : //github.com/nuxt/nuxt.js/issues/2912 - 尽管这必须是一个非常常规的用例。
Simple string replacement should suffice.简单的字符串替换就足够了。
const string = 'links are outputted like so: <a href="#">. How can I replace this content with: <nuxt-link to="#">' const converted = string.replace(/<a/g, '<nuxt-link').replace(/href=/g, 'to='); console.log(converted)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.