1

I stuck with some strange behaviour in vue.

The result

enter image description here

The code

<template>
  <div class="container">
    <main class="messages">
      <message v-for="message in messages" v-bind="message" :key="message.id" />
    </main>
    <div class="send-message">
      <g-input v-model="message" :maxLength="80" @submit="sendMessage">
        <object type="image/svg+xml" data="assets/send-icon.svg" width="200" height="200">
          <img src="assets/send-icon.png" width="200" height="200" alt="image format png" />
        </object>
      </g-input>
    </div>
  </div>
</template>

g-input code

<template>
  <div class="root">
    <canvas ref="canvas" class="hide"></canvas>
    <textarea
      ref="input"
      class="input"
      type="text"
      :rows="lineCount"
      :maxlength="maxLength"
      :value="value"
      @input="handleInput"
      @keydown.prevent.enter="handleEnter"
    />
    <div ref="confirmButton" class="confirm-button">
      <slot></slot>
    </div>
    <span class="char-counter">{{ `${charCount}/${maxLength}` }}</span>
  </div>
</template>

I absolutely do not understand why this happens, can you please explain?

Gerpea
  • 309
  • 1
  • 3
  • 13

1 Answers1

1

So I found how to avoid this

Just need to replace data attribute in object like this

<object type="image/svg+xml" :data="sendIcon" width="200" height="200">
    <img src="@/assets/send-icon.png" width="200" height="200" alt="image format png" />
</object>

Then in script tag we need to export icon

const sendIcon = require('@/assets/send-icon.svg')

export default {
  data: () => ({
    sendIcon: sendIcon,
  }),
}

But I still do not understand wht this is happens cause single <img> tag works just fine

<img src="@/assets/send-icon.svg" width="200" height="200" alt="image format png" />

And only <object> tag produce this behaviour and only with local url, some http url works fine

<object
    type="image/svg+xml"
    data="https://upload.wikimedia.org/wikipedia/commons/1/12/Black_Paw.svg"
    width="200"
    height="200">
    <img
        src="https://upload.wikimedia.org/wikipedia/commons/1/12/Black_Paw.svg"
        width="200"
        height="200"
        alt="image format png"
    />
</object>
Gerpea
  • 309
  • 1
  • 3
  • 13