Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: ウォッチャーのサンプルを少し親切にする #327

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,21 @@ const randomComputed = computed(() => {

```vue
<script setup>
import { ref, computed, watch } from "vue";
import { ref, watch } from "vue";

const count = ref(1);
const histories = ref([[count.value, null]]);
// 今の値とひとつ前の値の配列のリアクティブな値
const histories = ref([{ current: count.value, prev: null }]);
watch(count, (current, prev) => {
histories.value.splice(0, 0, [current, prev]);
// 配列の先頭に値を追加する
histories.value.splice(0, 0, { current, prev });
});
</script>

<template>
<div>
<input type="number" v-model="count" />
<h3>値の履歴(nステップ前の値が表示されます)</h3>
<ol start="0">
<li v-for="(history, index) in histories" :key="index">
今の値: {{ history[0] }}、前の値: {{ history[1] ?? "なし" }}
Expand Down