vue dialog及detail封装

本文介绍了如何在Vue.js中封装对话框(Dialog)和详情(Detail)组件。首先,详细讲解了Dialog的封装过程,包括父组件的设置,view-module.js模块的实现,以及add-or-update.vue子组件的创建。接着,转向Detail封装,阐述了在父组件和子组件sub-detail中的具体实现步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、dialog封装

1.父组件

  <!-- 弹窗, 新增 / 修改 -->
  <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" 
       @refreshDataList="getDataList"></add-or-update>

 // 引入
 import mixinViewModule from '@/mixins/view-module'
 import AddOrUpdate from './add-or-update'

 components: {
    AddOrUpdate
  },

2.view-module.js

  // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    },

3.add-or-update.vue

<el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()"
               label-width="100px">
          <el-form-item label="主题名称" prop="name">
              <el-input v-model="dataForm.name" placeholder="单行输入" maxlength="4" auto-complete="false" clearable v-bind:disabled="edit">
              </el-input>
          </el-form-item>
      </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
    </template>
  </el-dialog>

4.

 data () {
    return {
      visible: false,
      dataForm: {
        id: '',
        name: ''
      }
    }
 computed: {
    edit () {
      if (this.dataForm.id) {
        return true
      }
      return false
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          // this.getInfo()
        }
        // this.getCustomerInfo()
      })
    },
}

5.

// 成功后  
this.$emit('refreshDataList')

二、detail封装

1.父组件中:

 <detail v-show="detailVisiable" ref="detail"></detail>

// 引入
import mixinViewModule from '@/mixins/view-module'

  components: {
    AddOrUpdate,
    Detail
  },

data() {
 detailVisiable: false
},

 showDetail(id, type) {
      // console.log('detail id: ' + id)
      this.detailVisiable = true
      this.$nextTick(() => {
        this.$refs.detail.id = id
        this.$refs.detail.prdType = type
        this.$refs.detail.init()
      })
    },

2.sub-detail组件中:

<template>
  <el-dialog
    :visible.sync="visible"
    title="子订单详情"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :append-to-body="true"
    class="allow-dialog"
  >
    <el-card shadow="never" class="box-card mb20">


 data() {
    return {
      visible: false,
      priceInfoArr: [],
      id: '',
      prdType: ''
    }
  },

 methods: {
    init() {
      console.log('detail init...')
      // console.log(this.id, 'this.id')
      // console.log(this.prdType, 'this.prdType-service')
      this.visible = true
      this.$nextTick(() => {
        if (this.id) {
          this.priceInfoArr = []
          this.getSubInfo(this.id, this.prdType)
        }
      })
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值