webfansplz / vuejs-challenges

Collection of Vue.js challenges
https://vuejs-challenges.netlify.app/
MIT License
2.69k stars 188 forks source link

12 - 优化性能的指令 #2718

Open Ly-TiR opened 2 months ago

Ly-TiR commented 2 months ago
//  v-once
<script setup>
import { ref } from 'vue';

const count = ref(0);

setInterval(() => {
  count.value++;
}, 1000);
</script>

<template>
  <span v-once>Make it never change: {{ count }}</span>
</template>
//  v-memo="[]"
<script setup>
import { ref } from 'vue';

const count = ref(0);

setInterval(() => {
  count.value++;
}, 1000);
</script>

<template>
  <span v-memo="[]">Make it never change: {{ count }}</span>
</template>