I'm using Material Design's Vue component icon set. I'd like to process a string to include an icon in the middle.
Input (a string I can't control):
"I want an icon to go there"
Desired output:
"I want an
<timer-icon></timer-icon>to go there"
I'm trying to do this using a method that processes the text. But how can I get my icon component in there?
I've tried this:
<template>
<span>{{ insertIcon(myString) }}</span>
</template>
import TimerIcon from 'vue-material-design-icons/Timer.vue'
export default {
data () {
return {
myString: fromAnotherPlugin // "I want an icon to go there"
}
},
components: {
TimerIcon
},
methods: {
insertIcon: function (string) {
return string.replace('icon', TimerIcon)
}
}
}
But it returns [object Object] in place of "icon."
I've also tried referencing the component as HTML.
<template>
<span>{{ insertIcon(myString) }}</span>
</template>
import TimerIcon from 'vue-material-design-icons/Timer.vue'
export default {
data () {
return {
myString: fromAnotherPlugin // "I want an icon to go there"
}
},
components: {
TimerIcon
},
methods: {
insertIcon: function (string) {
return string.replace('icon', '<TimerIcon></TimerIcon>')
}
}
}
But it comes back empty.
components: { MenuIcon }and when using it don't use PascalCase use kebab-case like so<timer-icon />