V
V
Vladimir Golub2020-10-05 13:03:20
Vue.js
Vladimir Golub, 2020-10-05 13:03:20

How to wrap a piece of dynamic content in a tag with SSR?

Task: wrap time (format - 28.09.2020 12:18) in span

I try like this

<template>
...
  <p class="lf-news-item__date">{{ addTimeSpan(item.date) }}</p>
...
</template>
...
    methods: {
      addTimeSpan(date) {
        if (process.client) {
          let dateArr = date.split(' ');
          let span = document.createElement('span');
          span.innerHTML = dateArr[1];

          return `${ dateArr[0] } ${ span }`
        } else {
          return date;
        }
      }
    },
...


But instead of span outputs [object HTMLSpanElement]

v-html doesn't work with functions at all.

What is the best way to withdraw?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VegasChickiChicki, 2020-10-05
@RazerVG

<template>
...
  <p class="lf-news-item__date">
    <span> {{ item.date.split(' ')[0] }} </span>
  </p>
...
</template>

What's the problem with doing this?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question