我从CMS系统(WordPress)检索内容。在“ page.content”变量中,链接输出如下:<a href="#">
。如何在客户端用以下内容替换此内容:<nuxt-link to="#">
?
之前曾有人问过这个问题,但没有真正的答案:https://github.com/nuxt/nuxt.js/issues/2912-尽管这一定是一个很常规的用例。
答案 0 :(得分:2)
简单的字符串替换就足够了。
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)