将<a>链接替换为<nuxt-link>字符串变量



我从CMS系统(WordPress(中检索内容。在"page.content"变量中,链接的输出方式如下:<a href="#">。如何在客户端将此内容替换为:<nuxt-link to="#">

这个问题以前有人问过,但没有真正的答案:https://github.com/nuxt/nuxt.js/issues/2912-尽管这一定是一个非常常见的用例。

简单的字符串替换就足够了。

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)

最新更新