Answer the question
In order to leave comments, you need to log in
How to replace shortcodes with components?
How to replace shortcode with component after parsing and substitution ?
import Vue from 'vue';
import TitleElementNew from '@/components/elements/TitleElementNew';
export default {
name: "ContentArticle",
data: function () {
return {
text: '<p>Hello world {sample}</p>',
}
},
methods: {
replaceShortCodes(text) {
text = text.replace('{sample}', `<TitleElementNew>H</TitleElementNew>`);
return text;
}
},
render: function(createElement) {
const template = this.replaceShortCodes(this.text)
const component = Vue.component('cont', {
template: template,
components: {
'TitleElementNew': TitleElementNew
}
})
return createElement(
'div',
{
class: 'content-article',
},
[
createElement(component)
]
)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question