<template>
<div>
<!-- 動態(tài)組件 -->
<component :is="currentComponent" v-bind="componentProps"></component>
<!-- 按鈕用于切換組件 -->
<el-button @click="switchComponent">切換組件</el-button>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { ElButton, ElInput } from 'element-plus';
// 使用 ref 創(chuàng)建響應式引用
const currentComponent = ref('ElButton');
const componentProps = ref({});
// 切換組件的函數(shù)
function switchComponent() {
// 切換組件類型
currentComponent.value = currentComponent.value === 'ElButton' ? 'ElInput' : 'ElButton';
// 你可以在這里設置不同組件的 props
if (currentComponent.value === 'ElInput') {
componentProps.value = { placeholder: '請輸入內容' };
} else {
componentProps.value = {};
}
}
</script>
因篇幅問題不能全部顯示,請點此查看更多更全內容
Copyright ? 2019- 91gzw.com 版權所有 湘ICP備2023023988號-2
違法及侵權請聯(lián)系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市萬商天勤律師事務所王興未律師提供法律服務