I have a body property in my data
data(){
return{
body:'Hello! I am @user3 and @user4'
}
}
I am looking to transform each @user into a clickable link that redirects to their specific URL path.
<router-link :to="`/${username1}`">@{{username1}}</router-link>
My Attempt
<span v-html='bodyReplaced'>
computed: {
bodyReplaced(){
return this.body.replace(
/@\w+/g,
(user) => '<router-link :to="`/${username1}`">@{{username1}}</router-link>'
)
}
}
Outcome of the code:
- The transformation was successful in the DOM but not visible in the view
- I am struggling with replacing the @ symbol after the match so it can be used in the 'to' attribute like: "`/${username1}