I have a body property in data
data(){
return{
body:'Hello im @username1 and @username2'
}
}
I want to convert each @user into a code below, where a user can click that link to go that url path.
<router-link :to="`/${username1}`">@{{username1}}</router-link>
What i tried
<span v-html='bodyReplaced'>
computed: {
bodyReplaced(){
return this.body.replace(
/@\w+/g,
(user) => '<router-link :to="`/${username1}`">@{{username1}}</router-link>'
)
}
}
What the code did:
- Convert the string into router-link in the dom but not in the view
- I dont know how to replace the @ after the match, so i can use it in to="`/${username1}