0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vue.jsのv-bindでhtmlを渡したい

Last updated at Posted at 2019-12-08

問題

Titleコンポーネントを作った際に<br>付きの値を渡したら<br>ごと反映されてしまった

スクリーンショット 2019-12-08 20.05.10.png
Title.vue
<template>
  <div class="title">
    <p class="title__lead__top">{{ top }}</p>
    <h2 class="title__catch">{{ catchCopy }}</h2>
    <p class="title__lead__bottom">
      {{ bottom }}
    </p>
  </div>
</template>

<script>
export default {
  name: "Title",
  data() {
    return {};
  },
  props: {
    top: {
      type: String,
      require: false,
      default: "top"
    },
    catchCopy: {
      type: String,
      require: true
    },
    bottom: {
      type: String,
      require: false,
      default: "bottom"
    }
  }
};
</script>

<style scoped></style>
Home.vue
<Title
top="キャッチコピー説明(top)"
catch-copy="キャッチコピー<br>キャッチコピー02<br>キャッチコピー03"
bottom="キャッチコピー説明(bottom)"
></Title>

解決方法

文字列をそのまま渡してしまっていたのでv-htmlディレクティブをつかう

スクリーンショット 2019-12-08 20.14.33.png
Title.vue
<template>
  <div class="title">
    <p class="title__lead__top">{{ top }}</p>
    <h2 class="title__catch" v-html="catchCopy"></h2>
    <p class="title__lead__bottom">
      {{ bottom }}
    </p>
  </div>
</template>

<script>
export default {
  name: "Title",
  data() {
    return {};
  },
  props: {
    top: {
      type: String,
      require: false,
      default: "top"
    },
    catchCopy: {
      type: String,
      require: true
    },
    bottom: {
      type: String,
      require: false,
      default: "bottom"
    }
  }
};
</script>

<style scoped></style>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?