这段代码演示了在Vue 3中使用
实现该函数式组件 :
-
使用
list
数据渲染列表元素 (ul/li) -
当点击列表子元素时,将其文本颜色更改为红色
<script setup lang='ts'>
import {
ref,defineComponent, h } from "vue"
/**
* Implement a functional component :
* 1. Render the list elements (ul/li) with the list data
* 2. Change the list item text color to red when clicked.
*/
const ListComponent = defineComponent({
props:{
list:Array,
activeIndex:Number
},
emits:["toggle"]