欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue實現(xiàn)選項卡案例

 更新時間:2022年03月01日 17:10:53   作者:_筱龍  
這篇文章主要為大家詳細介紹了vue實現(xiàn)選項卡案例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue實現(xiàn)選項卡案例的具體代碼,供大家參考,具體內(nèi)容如下

實現(xiàn)步驟

實現(xiàn)靜態(tài)UI效果

  • 用傳統(tǒng)的方式實現(xiàn)標簽結構和樣式

基于數(shù)據(jù)重構UI效果

  • 將靜態(tài)的結構和樣式重構為基于Vue模板語法的形式
  • 處理事件綁定和js控制邏輯

聲明式編程

  • 模板的結構和最終顯示的效果基本一致

我們先把每組數(shù)據(jù)作為對象存儲在數(shù)組中

list: [{
? ? ? id: 1,
? ? ? title: 'apple',
? ? ? path: 'images/蘋果.jpg'
? ? ? }, {
? ? ? ? ?id: 2,
? ? ? ? ?title: 'orange',
? ? ? ? ?path: 'images/橘子.jpg'
? ? ? }, {
? ? ? ? ?id: 3,
? ? ? ? ?title: 'lemon',
? ? ? ? ?path: 'images/檸檬.jpg'
? ? ? }]

然后通過v-for對這個數(shù)組進行遍歷,取到對應的title值

<li :key='item.id' v-for='(item,index) in list'>{{item.title}}</li>

對圖片也進行遍歷

<div :key='item.id' v-for='(item,index) in list'>
? ? ? <img src="item.path">
</div>

具體代碼如下

<!DOCTYPE html>
<html lang="en">

<head>
? ? <meta charset="UTF-8">
? ? <meta name="viewport" content="width=device-width, initial-scale=1.0">
? ? <title>Document</title>
? ? <style>
? ? ? ? .tab ul {
? ? ? ? ? ? overflow: hidden;
? ? ? ? ? ? padding: 0;
? ? ? ? ? ? margin: 0;
? ? ? ? }
? ? ? ??
? ? ? ? .tab ul li {
? ? ? ? ? ? box-sizing: border-box;
? ? ? ? ? ? padding: 0;
? ? ? ? ? ? float: left;
? ? ? ? ? ? width: 100px;
? ? ? ? ? ? height: 45px;
? ? ? ? ? ? line-height: 45px;
? ? ? ? ? ? list-style: none;
? ? ? ? ? ? text-align: center;
? ? ? ? ? ? border-top: 1px solid blue;
? ? ? ? ? ? border-right: 1px solid blue;
? ? ? ? ? ? border-bottom: 1px solid blue;
? ? ? ? ? ? cursor: pointer;
? ? ? ? }
? ? ? ??
? ? ? ? .tab ul li:first-child {
? ? ? ? ? ? border-left: 1px solid blue;
? ? ? ? }
? ? ? ??
? ? ? ? .tab ul li.active {
? ? ? ? ? ? background-color: orange;
? ? ? ? }
? ? ? ??
? ? ? ? .tab div {
? ? ? ? ? ? width: 500px;
? ? ? ? ? ? height: 300px;
? ? ? ? ? ? display: none;
? ? ? ? ? ? text-align: center;
? ? ? ? ? ? font-style: 30px;
? ? ? ? ? ? line-height: 300px;
? ? ? ? ? ? border: 1px solid blue;
? ? ? ? ? ? border-top: 0px;
? ? ? ? }
? ? ? ??
? ? ? ? .tab div.current {
? ? ? ? ? ? margin-top: 0px;
? ? ? ? ? ? width: 300px;
? ? ? ? ? ? height: 300px;
? ? ? ? ? ? display: block;
? ? ? ? }
? ? ? ??
? ? ? ? img {
? ? ? ? ? ? width: 300px;
? ? ? ? ? ? height: 300px;
? ? ? ? }
? ? </style>
</head>

<body>
? ? <div id="app">
? ? ? ? <div class="tab">
? ? ? ? ? ? <ul>
? ? ? ? ? ? ? ? <li v-on:click='change(index)' :class='currentIndex==index?" active":""' :key='item.id' v-for='(item,index) in list'>{{item.title}}</li>

? ? ? ? ? ? </ul>
? ? ? ? ? ? <div :class='currentIndex==index?"current":""' :key='item.id' v-for='(item,index) in list'>
? ? ? ? ? ? ? ? <img :src="item.path">
? ? ? ? ? ? </div>
? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? <img src="images/檸檬.jpg">
? ? ? ? ? ? </div>
? ? ? ? </div>
? ? </div>
? ? <script type="text/javascript" src="js/vue.js"></script>
? ? <script type="text/javascript">
? ? ? ? var vm = new Vue({
? ? ? ? ? ? el: '#app',
? ? ? ? ? ? /*數(shù)據(jù)*/
? ? ? ? ? ? data: {
? ? ? ? ? ? ? ? currentIndex: 0,
? ? ? ? ? ? ? ? /*當前索引*/
? ? ? ? ? ? ? ? list: [{
? ? ? ? ? ? ? ? ? ? id: 1,
? ? ? ? ? ? ? ? ? ? title: 'apple',
? ? ? ? ? ? ? ? ? ? path: 'images/蘋果.jpg'
? ? ? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? ? ? id: 2,
? ? ? ? ? ? ? ? ? ? title: 'orange',
? ? ? ? ? ? ? ? ? ? path: 'images/橘子.jpg'
? ? ? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? ? ? id: 3,
? ? ? ? ? ? ? ? ? ? title: 'lemon',
? ? ? ? ? ? ? ? ? ? path: 'images/檸檬.jpg'
? ? ? ? ? ? ? ? }]
? ? ? ? ? ? },

? ? ? ? ? ? /*js控制邏輯*/
? ? ? ? ? ? methods: {
? ? ? ? ? ? ? ? // 在這里實現(xiàn)選項卡切換操作:本質(zhì)就是操作類名
? ? ? ? ? ? ? ? // 如何操作類名?就是通過currentIndex
? ? ? ? ? ? ? ? change: function(index) {
? ? ? ? ? ? ? ? ? ? this.currentIndex = index
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? })
? ? </script>
</body>

</html>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • vue中filter的應用場景詳解

    vue中filter的應用場景詳解

    這篇文章主要為大家介紹了vue中filter的應用場景,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • vue+express+jwt持久化登錄的方法

    vue+express+jwt持久化登錄的方法

    這篇文章主要介紹了vue+express+jwt持久化登錄的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-06-06
  • VUE實現(xiàn)移動端列表篩選功能

    VUE實現(xiàn)移動端列表篩選功能

    這篇文章主要介紹了VUE實現(xiàn)移動端列表篩選功能,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-08-08
  • 淺談vue中computed屬性對data屬性賦值為undefined的原因

    淺談vue中computed屬性對data屬性賦值為undefined的原因

    本文主要介紹了淺談vue中computed屬性對data屬性賦值為undefined的原因,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • Vue分頁組件實現(xiàn)過程詳解

    Vue分頁組件實現(xiàn)過程詳解

    Web應用程序中資源分頁不僅對性能很有幫助,而且從用戶體驗的角度來說也是非常有用的。在這篇文章中,將了解如何使用Vue創(chuàng)建動態(tài)和可用的分頁組件
    2022-12-12
  • Vue中獲取this.$refs為undefined的問題

    Vue中獲取this.$refs為undefined的問題

    這篇文章主要介紹了Vue中獲取this.$refs為undefined的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • vue 使用eventBus實現(xiàn)同級組件的通訊

    vue 使用eventBus實現(xiàn)同級組件的通訊

    這篇文章主要介紹了vue 使用eventBus實現(xiàn)同級組件的通訊,需要的朋友可以參考下
    2018-03-03
  • Vue.js基礎之監(jiān)聽子組件事件v-on及綁定數(shù)據(jù)v-model學習

    Vue.js基礎之監(jiān)聽子組件事件v-on及綁定數(shù)據(jù)v-model學習

    這篇文章主要為大家介紹了Vue.js基礎之監(jiān)聽子組件事件v-on及綁定數(shù)據(jù)v-model學習,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • vue mounted組件的使用

    vue mounted組件的使用

    這篇文章主要介紹了vue mounted組件的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • vue如何修改data中數(shù)據(jù)問題

    vue如何修改data中數(shù)據(jù)問題

    這篇文章主要介紹了vue如何修改data中數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09

最新評論