Как заменить шорткоды на компоненты?

Как заменить шорткод на компонент после парсинга и подстановки ?
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)
        ]
      )
    }
  }

Пробую через Vue.component, но возникают ошибки ?
  • Вопрос задан
  • 59 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы