データバインドを一度だけ行うv-once

date
Mar 6, 2023
repo_url
slug
vonce
status
Published
summary
type
Post
thumbnail_url
tags
vue
outer_link
v-onceは最初の1回だけデータバインドを行う。
<script setup lang="ts">
import { ref } from 'vue';

const price = ref(1000);
</script>

<template>
  <section>
    <input type="number" v-model="price" /><br />
    <!--↓inputが変わる度に変わる-->
    <p>金額は{{ price }}円です。</p>
    <!--↓初期値の1000から変わらない-->
    <p v-once>金額は{{ price }}円です。</p>
  </section>
</template>
 

© Hayato Kamiyama 2023 - 2024 - Build with Next.js & Notion