美文网首页
Vue3中computed的使用

Vue3中computed的使用

作者: 小李不小 | 来源:发表于2021-06-21 18:12 被阅读0次

vue3中computed的写法

<template>
  <div>
    <p><input type="text" v-model="age"></p>
    <p><input type="text" v-model="nextAge"></p>
  </div>
</template>

<script>
import { computed, ref } from 'vue'
export default {
  setup() {
    const age = ref(18)
    const nextAge = computed(() => {
      return +age.value + 1
    })
    return { 
      age,
      nextAge
    }
  }
}

相关文章

网友评论

      本文标题:Vue3中computed的使用

      本文链接:https://www.haomeiwen.com/subject/wenqyltx.html