Vue3利用父子组件实现字典

子组件

<template>
    <div>
        <el-tag :type="tagType" v-if="tagVisible">{
  { tagText }}</el-tag>
    </div>
</template>


<script setup>
import {
      defineProps, onMounted, ref } from 'vue'

const tagVisible = ref(false);
const tagType = ref("info");
const tagText = ref("");

// 定义参数 已经选中的ITEMID
const props = defineProps({
     
  dictType: {
     
    type: String, //参数类型
    default: String, //默认值
    required: true, //是否必须传递
  },
  dictValue: {
     
    type: String, //参数类型
    default: String, //默认值
    required: true, //是否必须传递
  }
})

const lastLogStatusDict = [
  {
     
    dictValue: 0,
    tagType: "primary",
    tagText: "运行中"
  },
  {
     
    dictValue: 1,
    tagType: "primary",
    tagText: "运行中"
  },
  {
     
    dictValue: 2,
    tagType: "danger",
    tagText: "异常"
  }
]

// //周期函数
onMounted(() => {
     
	//打印父组件传递的值
  // console.log(props.dictType, 'dictType');
  // console.log(props.dictValue, 'dictValue');

  const dictType = props.dictType;
  const dictValue = props.dictValue;
  
  if(dictValue==null){
     
    return;
  }
  tagVisible.value = true;

  if(dictType == "lastLogStatus"){
     
      tagType.value = lastLogStatusDict[dictValue].tagType;
      tagText.value = lastLogStatusDict[dictValue].tagText;
  }

})
</script>

父组件

<DictTag dictType="lastLogStatus" :dictValue="scope.row.lastLogStatus"/>

import DictTag from '@/components/dict/index.vue'

相关推荐

  1. Vue3利用父子组件实现字典

    2024-02-22 07:42:02       56 阅读
  2. Vue3父子组件通信

    2024-02-22 07:42:02       62 阅读
  3. vue3父子组件传值

    2024-02-22 07:42:02       58 阅读
  4. vue3利用自定义事件和v-model实现父子传参

    2024-02-22 07:42:02       61 阅读
  5. vue3+vite+ts父子组件之间的传值

    2024-02-22 07:42:02       70 阅读
  6. vue3父子组件之间的传值方式

    2024-02-22 07:42:02       46 阅读
  7. Vue3父子组件的传值问题

    2024-02-22 07:42:02       31 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-22 07:42:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-22 07:42:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-22 07:42:02       82 阅读
  4. Python语言-面向对象

    2024-02-22 07:42:02       91 阅读

热门阅读

  1. linux系统离线安装docker服务教程

    2024-02-22 07:42:02       57 阅读
  2. 深度学习基础之《TensorFlow框架(5)—会话》

    2024-02-22 07:42:02       56 阅读
  3. select滑动分页请求数据

    2024-02-22 07:42:02       51 阅读
  4. springboot 控制层 aop 日志

    2024-02-22 07:42:02       50 阅读
  5. 深度学习????????

    2024-02-22 07:42:02       53 阅读
  6. BeautifulSoup的使用与入门

    2024-02-22 07:42:02       50 阅读
  7. 计算机科学背后的故事和挑战

    2024-02-22 07:42:02       57 阅读
  8. 设计模式-策略模式

    2024-02-22 07:42:02       50 阅读
  9. 高级统计方法 第1次作业

    2024-02-22 07:42:02       52 阅读
  10. nginx的配置文件详解

    2024-02-22 07:42:02       43 阅读
  11. day38打卡

    2024-02-22 07:42:02       53 阅读