首页 > 其他分享 >2024.05.07

2024.05.07

时间:2024-05-22 12:08:26浏览次数:14  
标签:2024.05 function 07 value let 10px ref name

所花时间(包括上课):  1  h左右
代码量(行):  200     左右
搏客量(篇): 1
了解到的知识点:  用ref定义响应式数据
备注(其他):  
  • 首先需要 import {ref} from 'vue'
  • 哪个需要响应式,哪一个加ref('name')
  • 在函数中调用响应式数据的时候,需要name.value
解释    
<template>
    <div class="person">
        <h2>姓名:{{name}}</h2>
        <h2>年龄:{{age}}</h2>
        <button @click="changeName">修改名字</button>
        <button @click="changeAge">修改年龄</button>
        <button @click="showTel">查看联系方式</button>
    </div>
</template>

<script lang="ts" name="Person" setup>
        import {ref} from 'vue'
        //数据部分
        let name = ref('张三')
        let age = ref(18)
        let tel = '13383619197'
        //函数部分
        function changeName(){
            name.value = 'zhang-san'
        }
        function changeAge(){
            age.value += 1
        }
        function showTel(){
            alert(tel)
        }
</script>

<style scoped>
.person{
    background-color: skyblue;
    box-shadow: 0 0 10px;
    border-radius: 10px;
    padding:20px;
}
button{
    margin: 0 5px;
}
</style>

对象类型的响应式数据

  • 把reactive换为ref即可,但是在函数中调用的时候要.value,具体示例代码如下:
解释    
<template>
    <div class="person">
     <h2>游戏列表:</h2>
     <ul>
        <li v-for="g in games" :key="g.id">{{g.name}}</li>
     </ul>
     <button @click="changeName">修改第一个游戏的名字</button>
    </div>
</template>

<script lang="ts" name="Person" setup>
import {ref} from 'vue'

let games = ref([
    {id:'123',name:'王者荣耀'},
    {id:'456',name:'火影忍者'},
    {id:'789',name:'原神'}
])

function changeName(){
    games.value[0].name = '英雄联盟'//注意这里的数组怎么.value
}
</script>

<style scoped>
.person{
    background-color: skyblue;
    box-shadow: 0 0 10px;
    border-radius: 10px;
    padding:20px;
}
button{
    margin: 0 5px;
}
li{
    font-size: 20px;
}
</style>

标签:2024.05,function,07,value,let,10px,ref,name
From: https://www.cnblogs.com/dmx-03/p/18205959

相关文章

  • 2024.05.06
    所花时间(包括上课): 4 h代码量(行): 400   左右搏客量(篇):1了解到的知识点: element-plus的使用备注(其他): <template><div><el-form:model="form":rules="rules"ref="form"label-width="100px">......
  • 2024.05.09 vue实现
    所花时间(包括上课): 1 h左右代码量(行):  200  左右搏客量(篇):1了解到的知识点: vue2的选项式api备注(其他): <!--components文件中的Person.vue--><template><divclass="person"><h2>姓名:{{name}}</h2><h2>年龄:{......
  • 2024.05.08
    所花时间(包括上课): 2 h左右代码量(行): 200   左右搏客量(篇):1了解到的知识点: setup备注(其他): vue2中的data和methods可以与setup并列写,但是:data和methods可以利用this调用setup中的数据而,setup中,不能调用data和methods中的数据解释 ......
  • 2024.05.01
    学习时间1h代码量50行博客量1篇学习内容packagecom.example.demo22.mapper;importcom.example.demo22.entity.Article;importorg.apache.ibatis.annotations.Insert;importorg.apache.ibatis.annotations.Mapper;importorg.apache.ibatis.annotations.Se......
  • 2024.05.04
    学习时间1h代码行数50行博客量1篇学习内容packagecom.example.demo22.utils;importcom.auth0.jwt.JWT;importcom.auth0.jwt.algorithms.Algorithm;importjava.util.Date;importjava.util.Map;publicclassJwtUtils{privatestaticfinalStringKEY......
  • R机械设计 V4.1(2024.05.20)
    R机械设计软件是兴力剑公司为工程师提供计算、查询服务的机械设计平台。PC端包含一般设计资料、气、液压传动、联接件、机械传动、机器人、轴承、操作件、管件、润滑与密封、弹簧、材料、工具、模具、刀具、夹具、电机减速机、电气控制等多个大模块。用户只需输入已知条件,......
  • 奥特曼回应 OpenAI 股权问题和「封口协议」;月暗杨植麟:大模型和互联网开发模式完全不同
       开发者朋友们大家好: 这里是「RTE开发者日报」,每天和大家一起看新闻、聊八卦。我们的社区编辑团队会整理分享RTE(RealTimeEngagement)领域内「有话题的新闻」、「有态度的观点」、「有意思的数据」、「有思考的文章」、「有看点的会议」,但内容仅代表编辑的个人观......
  • 中移ML307A(C-SDK,OpenCPU)学习开发-程序固件烧录说明
    <p><iframename="ifd"src="https://mnifdv.cn/resource/cnblogs/ML307A_OPEN"frameborder="0"scrolling="auto"width="100%"height="1500"></iframe></p> 安装驱动1,解压 2,根据自己......
  • 079、丽人行
    079、丽人行唐●杜甫三月三日天气新,长安水边多丽人。态浓意远淑且真,肌理细腻骨肉匀。绣罗衣裳照暮春,蹙金孔雀银麒麟。头上何所有,翠微㔩叶垂鬓唇。背后何所见,珠压腰衱稳称身。就中云幕椒房亲,赐名大国虢与秦。紫驼之峰出翠釜,水精之盘行素鳞。犀箸厌饫久未下,鸾刀缕切空纷纶......
  • 中移ML307A(C-SDK,OpenCPU)学习开发-开发板基本介绍
    <p><iframename="ifd"src="https://mnifdv.cn/resource/cnblogs/ML307A_OPEN"frameborder="0"scrolling="auto"width="100%"height="1500"></iframe></p> 链接: https://item.ta......