Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 2.75 KB

File metadata and controls

45 lines (33 loc) · 2.75 KB

functional component medium #Components

By webfansplz @webfansplz

Take the Challenge    简体中文

For this challenge, we're going to implement a functional component. Lets go 👇:

<script setup lang='ts'>

import { ref } 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 = () => {
}

const list = [{
  name: "John",
}, {
  name: "Doe",
}, {
  name: "Smith",
}]

const activeIndex = ref(0)

function toggle(index: number) {
  activeIndex.value = index
}

</script>

<template>
  <list-component
    :list="list"
    :active-index="activeIndex"
    @toggle="toggle"
  />
</template>

Back Share your Solutions Check out Solutions