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

vue、uniapp實(shí)現(xiàn)組件動(dòng)態(tài)切換效果

 更新時(shí)間:2023年10月11日 09:28:22   作者:我總是詞不達(dá)意  
在Vue中,通過使用動(dòng)態(tài)組件,我們可以實(shí)現(xiàn)組件的動(dòng)態(tài)切換,從而達(dá)到頁(yè)面的動(dòng)態(tài)展示效果,這篇文章主要介紹了vue、uniapp實(shí)現(xiàn)組件動(dòng)態(tài)切換,需要的朋友可以參考下

在Vue中,通過使用動(dòng)態(tài)組件,我們可以實(shí)現(xiàn)組件的動(dòng)態(tài)切換,從而達(dá)到頁(yè)面的動(dòng)態(tài)展示效果。

vue 中 component組件 is屬性

 功能描述 

例如:有多個(gè)tabs標(biāo)簽,如:推薦、熱點(diǎn)、視頻等。用戶點(diǎn)擊標(biāo)簽就會(huì)切換到對(duì)應(yīng)組件

vue2版

<template>
	<!-- 標(biāo)簽數(shù)據(jù) -->
	<!-- uview-ui 標(biāo)簽組件 -->
	<u-tabs
		class="tabsBox"
		:list="tabData"
		@click="changeTab"
		:current="tabsCurrent"
	></u-tabs>
	<!-- 組件切換 -->
	<component :is="getCurrentCompName"></component>
</template>
<script>
import CompA from './components/comp-a.vue'
import CompB from './components/comp-b.vue'
import CompC from './components/comp-c.vue'
export default {
	data() {
		return {
			tabsCurrent: 0,
			tabsList: [],
		}
	},
	computed: {
		getCurrentCompName() {
			let currentCompName = ''
			switch (this.tabsCurrent) {
				case 1:
					currentCompName = 'CompB'
					break
				case 2:
					currentCompName = 'CompC'
					break
				default:
					currentCompName = 'CompA'
			}
			return currentCompName
		},
	},
	methods: {
		toggle(index) {
			this.tabsCurrent = index
		},
	},
}
</script>

vue3版

<template>
	<!-- 標(biāo)簽數(shù)據(jù) -->
	<!-- uview-ui 標(biāo)簽組件 -->
	<u-tabs
		class="tabsBox"
		:list="tabData"
		@click="changeTab"
		:current="tabsCurrent"
	></u-tabs>
	<!-- 組件切換 -->
	<component :is="getCurrentCompName"></component>
</template>
<script setup>
import { ref, reactive, markRaw} from 'vue';
import CompA from './components/comp-a.vue';
import CompB from './components/comp-b.vue';
import CompC from './components/comp-c.vue';
const tabsCurrent = ref(0);
const tabsList = ref([]);
const getCurrentCompName = () => {
	let currentCompName = '';
	switch (tabsCurrent.value) {
		case 1:
			currentCompName = markRaw(CompB);
			break;
		case 2:
			currentCompName = markRaw(CompC);
			break;
		default:
			currentCompName = markRaw(CompA);
	}
	return currentCompName;
};
const toggle = (index) => {
	tabsCurrent.value = index;
};
</script>

或者

<template>
	<!-- 標(biāo)簽數(shù)據(jù) -->
	<!-- uview-ui 標(biāo)簽組件 -->
	<u-tabs
		class="tabsBox"
		:list="tabData"
		@click="changeTab"
		:current="tabsCurrent"
	></u-tabs>
	<!-- 組件切換 -->
	<component :is="currentComp"></component>
</template>
<script setup>
import { ref, reactive, markRaw, shallowRef } from 'vue';
import CompA from './components/comp-a.vue';
import CompB from './components/comp-b.vue';
import CompC from './components/comp-c.vue';
const tabsCurrent = ref(0);
const tabsList = ref([]);
const currentComp = shallowRef(CompA)
const toggle = (index) => {
	tabsCurrent.value = index;
		switch (index) {
		case 1:
			currentComp.value = CompB;
			break;
		case 2:
			currentComp.value = CompC;
			break;
		default:
			currentComp.value = CompA;
	}
};
</script>

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

相關(guān)文章

  • Vue項(xiàng)目中引入 ECharts

    Vue項(xiàng)目中引入 ECharts

    這篇文章主要介紹了Vue項(xiàng)目中引入 ECharts,ECharts是一個(gè)強(qiáng)大的畫圖插件,在vue項(xiàng)目中,我們常常可以引用Echarts來完成完成一些圖表的繪制;以下介紹vue項(xiàng)目中引用并使用ECharts,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2021-12-12
  • vue如何給element-ui中的el-tabs動(dòng)態(tài)設(shè)置label屬性

    vue如何給element-ui中的el-tabs動(dòng)態(tài)設(shè)置label屬性

    這篇文章主要介紹了vue如何給element-ui中的el-tabs動(dòng)態(tài)設(shè)置label屬性,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue的export?default和帶返回值的data()及@符號(hào)的用法說明

    Vue的export?default和帶返回值的data()及@符號(hào)的用法說明

    這篇文章主要介紹了Vue的export?default和帶返回值的data()及@符號(hào)的用法說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • vue實(shí)現(xiàn)登錄數(shù)據(jù)的持久化的使用示例

    vue實(shí)現(xiàn)登錄數(shù)據(jù)的持久化的使用示例

    在Vue.js中,實(shí)現(xiàn)登錄數(shù)據(jù)的持久化需要使用瀏覽器提供的本地存儲(chǔ)功能,Vue.js支持使用localStorage和sessionStorage來實(shí)現(xiàn)本地存儲(chǔ),本文就來介紹一下如何實(shí)現(xiàn),感興趣的可以了解一下
    2023-10-10
  • vue.js高德地圖實(shí)現(xiàn)熱點(diǎn)圖代碼實(shí)例

    vue.js高德地圖實(shí)現(xiàn)熱點(diǎn)圖代碼實(shí)例

    這篇文章主要介紹了vue.js高德地圖實(shí)現(xiàn)熱點(diǎn)圖,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • vue級(jí)聯(lián)選擇器的getCheckedNodes使用方式

    vue級(jí)聯(lián)選擇器的getCheckedNodes使用方式

    這篇文章主要介紹了vue級(jí)聯(lián)選擇器的getCheckedNodes使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • Element輸入框帶歷史查詢記錄的實(shí)現(xiàn)示例

    Element輸入框帶歷史查詢記錄的實(shí)現(xiàn)示例

    這篇文章主要介紹了Element輸入框帶歷史查詢記錄的實(shí)現(xiàn)示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-01-01
  • vue中使用閉包(防抖和節(jié)流)失效問題

    vue中使用閉包(防抖和節(jié)流)失效問題

    本文主要介紹了vue中使用閉包(防抖和節(jié)流)失效問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Vue刷新修改頁(yè)面中數(shù)據(jù)的方法

    Vue刷新修改頁(yè)面中數(shù)據(jù)的方法

    今天小編就為大家分享一篇Vue刷新修改頁(yè)面中數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue中引入echarts的步驟及折線圖、柱狀圖常見配置項(xiàng)

    Vue中引入echarts的步驟及折線圖、柱狀圖常見配置項(xiàng)

    這篇文章主要介紹了Vue中引入echarts的步驟及折線圖、柱狀圖常見配置項(xiàng),需要的朋友可以參考下
    2023-11-11

最新評(píng)論

石渠县| 祁东县| 兰考县| 西藏| 大悟县| 汉川市| 颍上县| 高密市| 永修县| 西青区| 盈江县| 贡觉县| 庆安县| 房产| 揭西县| 蕉岭县| 故城县| 称多县| 宁国市| 德昌县| 阳城县| 伊川县| 云阳县| 衡水市| 即墨市| 克拉玛依市| 白河县| 菏泽市| 宾阳县| 绥江县| 西吉县| 靖州| 邢台县| 九台市| 东丰县| 铅山县| 团风县| 东平县| 秭归县| 临沭县| 宜黄县|