当前位置:网站首页>列表渲染 map 与 v-for

列表渲染 map 与 v-for

2022-08-11 05:17:00 -加油

1、react App.js

const songs = [
  {
    
    id: 1,
    name: 'hhhhh'
  },
  {
    
    id: 2,
    name: 'xxxxx'
  },
  {
    
    id: 3,
    name: 'aaaaa'
  }
]
function App() {
    
  return (
    <div className="App">
      <ul>
        {
    songs.map(song => <li key={
    song.id}>{
    song.name}</li>)}
      </ul>
    </div>
  );
}

export default App;

2、vue App.vue

<template>
  <div id="app">
    <ul v-for="song in songs" :key="song.id">
        <li>{
    {
    song.name}}</li>
    </ul>
  </div>
</template>
<script>
export default {
    
  data() {
    
    return {
    
      songs: [
        {
    
          id: 1,
          name: 'hhhhh'
        },
        {
    
          id:2,
          name:'xxxxx'
        },
        {
    
          id:3,
          name:'aaaaa'
        }
      ]
    }
  }
}
</script>

<style>
</style>

原网站

版权声明
本文为[-加油]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_51040174/article/details/125494244