最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實(shí)現(xiàn)組件切換效果的三種功能

 更新時(shí)間:2024年11月18日 10:50:33   作者:想你的風(fēng)吹到了瑞士  
這篇文章主要為大家介紹了在Vue中實(shí)現(xiàn)組件切換的三種方法,即使用條件渲染,使用動(dòng)態(tài)組件以及通過點(diǎn)擊按鈕切換組件,有需要的小伙伴可以了解下

一、使用條件渲染 (v-if)

<template>
    <div>
        <button @click="currentView = 'ComponentA'">Show Component A</button>
        <button @click="currentView = 'ComponentB'">Show Component B</button>
        <component-a v-if="currentView === 'ComponentA'"></component-a>
        <component-b v-if="currentView === 'ComponentB'"></component-b>
    </div>
</template>
<script>
import ComponentA from './ComponentA.vue';
import ComponentB from './ComponentB.vue';
export default {
    data() {
        return {
            currentView: 'ComponentA'
        };
    },
    components: {
        ComponentA,
        ComponentB
    }
};
</script>

二、使用動(dòng)態(tài)組件 (component)

<template>
    <div>
        <button @click="currentView = 'ComponentA'">Show Component A</button>
 
        <button @click="currentView = 'ComponentB'">Show Component B</button>
 
        <component :is="currentView"></component>
    </div>
</template>
 
<script>
import ComponentA from './ComponentA.vue';
 
import ComponentB from './ComponentB.vue';
 
export default {
    data() {
        return {
            currentView: 'ComponentA'
        };
    },
 
    components: {
        ComponentA,
 
        ComponentB
    }
};
</script>

 三、點(diǎn)擊按鈕切換組件

<template>
  <div>
    <button @click="toggleComponent">切換組件</button>
    <div v-if="showComponent">
      <ComponentA />
    </div>
    <div v-else>
      <ComponentB />
    </div>
  </div>
</template>
 
<script>
import ComponentA from './ComponentA.vue'
import ComponentB from './ComponentB.vue'
 
export default {
  data() {
    return {
      showComponent: true
    }
  },
  methods: {
    toggleComponent() {
      this.showComponent = !this.showComponent
    }
  },
  components: {
    ComponentA,
    ComponentB
  }
}
</script>
<template>
  <div>
    <button @click="toggleComponent">切換組件</button>
    <transition name="fade">
      <component :is="currentComponent" />
    </transition>
  </div>
</template>
 
<script>
import ComponentA from './ComponentA.vue'
import ComponentB from './ComponentB.vue'
 
export default {
  data() {
    return {
      currentComponent: 'ComponentA'
    }
  },
  methods: {
    toggleComponent() {
      this.currentComponent = this.currentComponent === 'ComponentA' ? 'ComponentB' : 'ComponentA'
    }
  },
  components: {
    ComponentA,
    ComponentB
  }
}
</script>
 
<style>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
 
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>

到此這篇關(guān)于vue實(shí)現(xiàn)組件切換效果的三種功能的文章就介紹到這了,更多相關(guān)vue組件切換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 基于Vue+Element?Plus實(shí)現(xiàn)組件遞歸調(diào)用的詳細(xì)步驟

    基于Vue+Element?Plus實(shí)現(xiàn)組件遞歸調(diào)用的詳細(xì)步驟

    在前端開發(fā)中,遞歸是一種非常強(qiáng)大的編程技術(shù),它允許函數(shù)或組件調(diào)用自身來解決問題,在Vue.js生態(tài)中,結(jié)合Element?Plus?UI庫,我們可以利用組件遞歸調(diào)用來構(gòu)建復(fù)雜的樹形結(jié)構(gòu),本文將深入探討Vue3與?Element?Plus中組件遞歸調(diào)用的實(shí)現(xiàn)原理、詳細(xì)步驟、最佳實(shí)踐
    2025-07-07
  • Element input樹型下拉框的實(shí)現(xiàn)代碼

    Element input樹型下拉框的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Element input樹型下拉框的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-12-12
  • 淺談Vant-list?上拉加載及下拉刷新的問題

    淺談Vant-list?上拉加載及下拉刷新的問題

    這篇文章主要介紹了淺談Vant-list?上拉加載及下拉刷新的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • Vite處理html模板插件之vite-plugin-html插件使用

    Vite處理html模板插件之vite-plugin-html插件使用

    這篇文章主要給大家介紹了關(guān)于Vite處理html模板插件之vite-plugin-html插件使用的相關(guān)資料,Vite是一個(gè)現(xiàn)代化的前端構(gòu)建工具,而vite-plugin-html是Vite的一個(gè)插件,用于在構(gòu)建時(shí)自動(dòng)生成HTML文件,需要的朋友可以參考下
    2023-10-10
  • unplugin-auto-import的配置以及eslint報(bào)錯(cuò)解決詳解

    unplugin-auto-import的配置以及eslint報(bào)錯(cuò)解決詳解

    unplugin-auto-import?解決了vue3-hook、vue-router、useVue等多個(gè)插件的自動(dòng)導(dǎo)入,也支持自定義插件的自動(dòng)導(dǎo)入,是一個(gè)功能強(qiáng)大的typescript支持工具,這篇文章主要給大家介紹了關(guān)于unplugin-auto-import的配置以及eslint報(bào)錯(cuò)解決的相關(guān)資料,需要的朋友可以參考下
    2022-08-08
  • vue多頁面項(xiàng)目開發(fā)實(shí)戰(zhàn)指南

    vue多頁面項(xiàng)目開發(fā)實(shí)戰(zhàn)指南

    一般我們的vue項(xiàng)目都是單頁面的,其實(shí)因?yàn)関ue在工程化開發(fā)的時(shí)候依賴了webpack,webpack幫我們將所有的資源整合到一起而形成一個(gè)單頁面,下面這篇文章主要給大家介紹了關(guān)于vue多頁面項(xiàng)目開發(fā)的相關(guān)資料,需要的朋友可以參考下
    2022-01-01
  • vue+vuex+axios實(shí)現(xiàn)登錄、注冊(cè)頁權(quán)限攔截

    vue+vuex+axios實(shí)現(xiàn)登錄、注冊(cè)頁權(quán)限攔截

    下面小編就為大家分享一篇vue+vuex+axios實(shí)現(xiàn)登錄、注冊(cè)頁權(quán)限攔截,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • vue項(xiàng)目中路由跳轉(zhuǎn)頁面不變問題及解決

    vue項(xiàng)目中路由跳轉(zhuǎn)頁面不變問題及解決

    這篇文章主要介紹了vue項(xiàng)目中路由跳轉(zhuǎn)頁面不變問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue項(xiàng)目添加動(dòng)態(tài)瀏覽器頭部title的方法

    Vue項(xiàng)目添加動(dòng)態(tài)瀏覽器頭部title的方法

    這篇文章主要介紹了Vue項(xiàng)目添加動(dòng)態(tài)瀏覽器頭部title的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-07-07
  • Vue組件模板的幾種書寫形式(3種)

    Vue組件模板的幾種書寫形式(3種)

    這篇文章主要介紹了Vue組件模板的幾種書寫形式(3種),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02

最新評(píng)論

荣成市| 教育| 沙田区| SHOW| 盘锦市| 政和县| 德钦县| 双柏县| 蓝田县| 唐河县| 通化市| 牡丹江市| 大新县| 甘洛县| 渭南市| 项城市| 常山县| 芒康县| 泰州市| 庄浪县| 张掖市| 嘉善县| 体育| 永定县| 微山县| 金昌市| 清涧县| 禄丰县| 德昌县| 信宜市| 镇沅| 响水县| 关岭| 无极县| 蕉岭县| 渝中区| 专栏| 格尔木市| 平泉县| 凉山| 澎湖县|