在视频通话应用中,当用户拨打电话时,需要在屏幕上显示通话中对方的个人信息,包括头像、姓名和职业等。
本代码实现了一个Vue.js组件,用于动态渲染通话中的医生信息卡片,包括以下功能:
在<script>
标签中,使用Vue.js的ref
函数创建三个响应式数据:doctorName
、doctorTitle
和doctorImage
,用于绑定医生的姓名、职业和头像。
const doctorName = ref('Dr. Pedro')
const doctorTitle = ref('Pediatrician')
const doctorImage = ref('https://source.unsplash.com/random/200x200')
在<template>
标签中,使用响应式数据绑定渲染医生信息卡片。其中,v-bind
指令用于将响应式数据绑定到HTML元素的属性上。
<div class="flex items-center justify-center mt-8">
<div class="w-24 h-24 rounded-full overflow-hidden">
<img :src="doctorImage" alt="Dr. Pedro" />
</div>
<div class="ml-4">
<h2 class="text-xl font-bold text-gray-900">{{ doctorName }}</h2>
<p class="text-sm text-gray-500">{{ doctorTitle }}</p>
</div>
</div>
开发这段代码的过程让我加深了对Vue.js响应式数据绑定的理解,并掌握了如何在Vue.js中动态渲染组件。
未来,可以对该卡片功能进行以下拓展和优化: