Skip to content

11 - 下一次DOM更新 #2288

Open
Open
@wxh233

Description

@wxh233
// 你的答案
<script setup>
import { nextTick, ref } from "vue"

const count = ref(0)
const counter = ref(null)


function increment() {
  count.value++

  /**
   * DOM is not yet updated, how can we make sure that the DOM gets updated
   * Make the output be true
  */
  nextTick(()=>{
   console.log(+counter.value.textContent === 1)
  })
 
}
</script>

<template>
  <button ref="counter" @click="increment">
    {{ count }}
  </button>
</template>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions