使用ref创建响应式数据 只支持 简单or 复杂 数据转换
使用ref:
1.导入ref函数
2.创建响应式数据
3.返回数据
4.展示内容
<template><p> 年龄:{{ count }}</p><button @click="count++">加一岁</button><button @click="increment()">加10岁</button>
</template>
<script>
/* 使用ref创建响应式数据 支持 简单or 复杂 数据转换在js中使用需要加 .value 在模板中不需要
*/
import { ref } from 'vue';export default{setup(){// 创建响应式数据const count = ref(0)const increment = () =>{// js中需要.valuecount.value += 10}// 返回数据return{count,increment}},}
</script>