Reputation: 6128
I retrieve content from a CMS system (WordPress). In the "page.content" variable, links are outputted like so: <a href="#">
. How can I replace this content with: <nuxt-link to="#">
on the client side?
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.
Upvotes: 1
Views: 2357
Reputation: 596
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)
Upvotes: 2