1.vue3.0中computed计算属性
<template>
<h1>vue3.0</h1>
数字一<input type="text" v-model="numList.firstNum">
<br>
<br>
数字二<input type="text" v-model="numList.lastNum">
<br>
<br>
总数<h3>{
{numList.lastNum}}</h3>
</template>
<script>
//从vue引入reactive computed属性
import {reactive,computed} from 'vue'
export default {
name: 'App',
setup(){
let numList =reactive({
firstNum:20,
lastNum:10
})
//返回结果
numList.totalNUm=computed(()=>{
return Number(numList.firstNum)+Number(numList.lastNum)
})
//最后return出去
return {
numList
}
}
}
</script>
注意:此处用的computed只返回结果 大多数使用这种方法比较多
2.computed的完整写法
<template>