[Vuejs]-How set dynamically jsonld in vue 3 ssr

1πŸ‘

βœ…

I writed fork head’s component of inertia js and change function renderTag in component. And it works.But with bugs

renderTag(node) {
  // check specific symbol from node.type
  switch (node.type.toString()) {
    case 'Symbol(Text)':
    case 'Symbol(v-txt)':
      return node.children
    case 'Symbol()':
    case 'Symbol(Comment)':
      return ''
    // if nothing expected, return a html string
    default:
      return this.renderTagStart(node) + 
      (node.children ? this.renderTagChildren(node) : '') +
      (!this.isUnaryTag(node) ? `</${node.type}>` : '')
  }
}
πŸ‘€Anton R

0πŸ‘

Create a new component with :

mounted () {

    const myJsonScript = document.createElement('script');
    myJsonScript.setAttribute('type', 'application/ld+json');
    myJsonScript.setAttribute('src', '...src...');
    myJsonScript.setAttribute('id', 'random_id');
    document.getElementById('app').appendChild(myJsonScript)
}

beforeDestroy () {
    document.getElementById('random_id').remove()
}

Use props for each attributes, then it should be close to your need.

In pure SSR, you can do something like this in template:

{{{ "&lt;script type='application/ld+json' &gt;{'key': " + value + "}&lt;/script&gt;" }}}
πŸ‘€pirs

Leave a comment