D
D
danyadev2018-11-18 10:26:58
Vue.js
danyadev, 2018-11-18 10:26:58

Why can't the text in the element be updated later when using the directive?

I have a directive with which you can make a normal display of emoji (from a simple emoji, an img is made with a picture of this emoji).
Here is the directive itself:

Vue.directive('emoji', (el) => {
  el.innerHTML = emoji(el.innerHTML);
});

Here is the template part:
<div class="conversation_name" v-emoji>{{ chatName }}</div>

chatName is a computed property that changes from time to time, but this does not happen using the directive. How to make everything work properly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-11-18
@danyadev

Vue.directive('emoji', (el, binding) => el.innerHTML = emoji(binding.value));

<div class="conversation_name" v-emoji="chatName"></div>

S
Stanislav Lashmanov, 2018-11-18
@CyberAP

Make a regular component instead of a directive, it fits more in its essence here.

export default {
  name: 'EmojiImage',
  props: {
    emoji: 'String'
  },
  computed: {
    image() {
      return ''; \\ Здесь сформируйте url картинки, это так же позволит использовать кэш, загружать их асинхронно
    }
  }

}

<template>
  <span class="emoji-image">
    <img :src="image" :alt="emoji" />
  </span>
</template>

<EmojiImage :emoji="emoji" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question