Skip to content

Instantly share code, notes, and snippets.

@MaxMonteil
Last active March 5, 2025 12:59
Show Gist options
  • Save MaxMonteil/fc3008bd2717570481bbd9caeb3340c7 to your computer and use it in GitHub Desktop.
Save MaxMonteil/fc3008bd2717570481bbd9caeb3340c7 to your computer and use it in GitHub Desktop.
Basic Vue interview
<template>
<h1>List items</h1>
<ul>
<li v-for="item in items" :key="item.id">
{{ item.name }}
</li>
</ul>
<button @click="addItem">Add item</button>
</template>
<script setup>
import { ref } from 'vue'
const items = ref([
{ name: "Item 1", id: 1 },
{ name: "Item 2", id: 2 },
{ name: "Item 3", id: 3 },
])
function addItem() {
const id = items.length + 1
items.push({ name: `Item ${id}`, id })
}
</script>
@MaxMonteil
Copy link
Author

React version:

export default function App() {
  const items = [
    { name: "Item 1", id: 1 },
    { name: "Item 2", id: 2 },
    { name: "Item 3", id: 3 },
  ];

  const addItem = () => {
    const id = items.length + 1;
    items.push({ name: `Item ${id}`, id })
  };

  return (
    <div>
      <h1>List items</h1>
      <ul>
        {items.map((item) => (
          <li key={item.id}>{item.name}</li>
        ))}
      </ul>
      <button onClick={addItem}>Add item</button>
    </div>
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment