您的位置:首页 > 文旅 > 美景 > 郴州疫情感染者名单_有效获客的六大渠道_网站推广优化的公司_网络优化工程师是干什么的

郴州疫情感染者名单_有效获客的六大渠道_网站推广优化的公司_网络优化工程师是干什么的

2025/2/13 10:45:20 来源:https://blog.csdn.net/weixin_37306719/article/details/143406925  浏览:    关键词:郴州疫情感染者名单_有效获客的六大渠道_网站推广优化的公司_网络优化工程师是干什么的
郴州疫情感染者名单_有效获客的六大渠道_网站推广优化的公司_网络优化工程师是干什么的

作用

ref用来定义:基本类型数据、对象类型数据

建议:基本类型数据用ref来定义;对象类型数据用reactive定义

ref定义的数据是响应式;

ref定义基本类型数据

Student.vue

<template>
<div><h2>{{ name }}</h2><h2>{{ age }}</h2><button @click="updateName">修改名字</button><button @click="updateAge">修改年龄</button><button @click="showPhone">显示联系方式</button>
</div>
</template><script setup lang="ts" name="Student">import { ref, Ref } from 'vue';let name=ref('weihu')let age=ref(18)function updateName(){name.value="李四"}function updateAge(){age.value+=1}function showPhone(){alert("18880709")}
</script><style scoped></style>

ref定义对象类型数据

Student.vue

<template>
<div><h2>ref定义对象类型数据</h2><h2>{{ studentInfo.name }}</h2><h2>{{ studentInfo.age }}</h2><button @click="updateName">修改名字</button><button @click="updateAge">修改年龄</button><button @click="showPhone">显示联系方式</button>
</div>
</template><script setup lang="ts" name="Student">import { ref, Ref } from 'vue';let studentInfo=ref({name:'weiwei',age:18})function updateName(){studentInfo.value.name="李四"}function updateAge(){studentInfo.value.age+=1}function showPhone(){alert("18880709")}
</script><style scoped></style>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com