vue computed的傳參和element-plus彈窗的顯示過程
更新時間:2026年03月25日 08:47:41 作者:白桃與貓
這篇文章主要介紹了vue computed的傳參和element-plus彈窗的顯示過程,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
1. vue3中computed的傳參使用
<template>
<el-tag :type="computedProcessTypeStyle(scope.row.processType)" size="large">
{{ computedProcessTypeName(scope.row.processType) }}
</el-tag>
</template>
<script setup lang="ts">
const computedProcessTypeStyle = computed(() => (type: string) => {
if (type === 'new' || type === 'fail') {
return 'danger';
}
if (type === 'processed') {
return 'success';
}
if (type === 'ticket') {
return '';
}
if (type === 'close') {
return 'info';
}
if (type === 'unknown') {
return 'warning';
}
});
</script>
2. element-plus彈窗的顯示(方法一)

使用該組件:

3. element-plus彈窗的顯示(方法二)
這種寫法和上面的寫法實現(xiàn)的效果一樣,都可用于值的雙向綁定,defineModel寫法更簡單!
注意是在<script setup >中使用
<template>
<el-dialog v-model="visible" title="選擇組件" width="35%" :height="600">
...
</el-dialog>
</template>
<script setup lang="ts">
const visible = defineModel('visible', { local: true, default: false });
</script>
引用組件處:
<template>
<ReportTreeDialog v-model:visible="reportTreeVisible" ></ReportTreeDialog>
</template>
<script setup lang="ts">
import ReportTreeDialog from './form-item/ReportTreeDialog.vue';
</script>
總結
- 計算數(shù)據(jù)變化后的結果:可以監(jiān)聽響應式數(shù)據(jù)的變化,一般計算購物車的總價或計算商品的平均評分
- 格式化數(shù)據(jù):過濾、排序數(shù)據(jù)
- 控制彈窗是否顯示
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
詳解vue-cli+element-ui樹形表格(多級表格折騰小計)
這篇文章主要介紹了vue-cli + element-ui 樹形表格(多級表格折騰小計),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04

