這篇文章將會詳細介紹一個Vue排名頁面的源碼,該頁面使用了Vue框架。以下是該頁面的代碼:
<template>
<div>
<h1>Top 10 Movies</h1>
<ul>
<li v-for="movie in topMovies" :key="movie.id">
{{ movie.name }} ({{ movie.rank }})<br>
{{ movie.description }}
</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
topMovies: [
{
id: 1,
name: 'Inception',
rank: 1,
description: 'A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.'
},
{
id: 2,
name: 'The Dark Knight',
rank: 2,
description: 'When the menace known as the Joker emerges from his mysterious past, he wreaks havoc and chaos on the people of Gotham. The Dark Knight must accept one of the greatest psychological and physical tests of his ability to fight injustice.'
},
// ...
{
id: 10,
name: 'Forrest Gump',
rank: 10,
description: 'The presidencies of Kennedy and Johnson, the events of Vietnam, Watergate, and other historical events unfold through the perspective of an Alabama man with an IQ of 75, whose only desire is to be reunited with his childhood sweetheart.'
}
]
}
}
}
</script>
該頁面使用了Vue框架,其主要功能是展示最受歡迎的電影排行榜top 10。以下是該頁面的詳細解釋:
1. 在模板標簽中,整個頁面被包括在一個div標簽內;
2. 通過h1標簽顯示排行榜名稱;
3. 使用v-for標簽來遍歷topMovies數組中的電影數據;
4. 使用:key屬性為每個列表項提供唯一標識符;
5. 在列表項中使用雙括號綁定每個電影的名稱、排名和描述。
在腳本部分,通過export default來導出當前組件,它包括data()方法,用來存儲topMovies數組,該數組的每個對象表示電影的id、名稱、排名和描述。
總之,這個Vue排名頁面源碼展示了使用Vue框架展示數據的一個基本范例。
上一篇vue接口的調用
下一篇vue接收http參數