vue element-ui 常见的新增、编辑、查看公用同一个页面

vue  element-ui 常见的新增、编辑、查看公用同一个页面


1.父组件代码篇(index.vue)

  • 父组件页面结构如下:
<template> 
  <div class="JNPF-common-layout">
    <el-table v-loading="listLoading" :data="list">
      <el-table-column prop="jhmc" label="辨识评价计划名称" align="left" />
	  <el-table-column prop="bskssj" label="辨识开始时间" align="left" />
      <el-table-column label="操作" fixed="right" width="200">
        <template slot-scope="scope">
          <!-- 按钮触发事件公用一个方法名addOrUpdateHandle() -->
  
	      <el-button type="text" @click="addOrUpdateHandle(scope.row.id)" >
            编辑
          </el-button>

          <el-button type="text" @click="addOrUpdateHandle(scope.row.id, true)" > 
            详情
          </el-button>
 
          <el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()">
	        新增
          </el-button> 

        </template>
      </el-table-column>
    </el-table>
    <!-- 用于引入子组件      @refresh自定义函数是用于刷新页面 -->
    <JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh" />
  </div>
</template> 
  • 父组件 addOrUpdateHandle()方法如下:
     

    <script>
      import JNPFForm from './form' // 引入子组件form表单
      export default {
        components: {JNPFForm}, // 注册子组件
        data() {
          return {
            formVisible: false,
          }
        },
        methods: { 
          // isDetail 是详情传过来的true的值,用来区分详情和查看
          addOrUpdateHandle(id,isDetail) {
            this.formVisible = true // 控制弹出框显示
            this.$nextTick(() => {
              this.$refs.JNPFForm.init(id,isDetail)  // init()是子组件函数
            })
          },
        },
      }
    </script>

    2.子组件代码篇(form.vue)关键代码

  •   子组件页面结构
<template>

  <!-- 关键代码::title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" -->

  <el-dialog :title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="800px">
    <el-row :gutter="15">

      <!-- :disabled="!!isDetail" 详情表单内容禁用状态 编辑为可编辑状态-->

      <el-form ref="elForm" :model="dataForm" label-width="139px" :disabled="!!isDetail">
        <el-col :span="24">
		  <el-form-item label="辨识评价计划名称" prop="jhmc" >
		    <el-input v-model="dataForm.jhmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
			</el-input>
		  </el-form-item>
		</el-col>
		<el-col :span="24">
		  <el-form-item label="辨识开始时间" prop="bskssj" >
			<el-date-picker v-model="dataForm.bskssj" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
			</el-date-picker>
		  </el-form-item>
		</el-col>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
	  <el-button @click="visible = false">取 消</el-button> 
	  <el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">
        确 定
      </el-button>
	</span>
  </el-dialog>
</template>
  • 子组件 init()方法
    <script>
      export default {
        data() {
          return {
            visible: false,
            dataForm: {}
          }
        },
        methods: {
    
          init(id, isDetail) {
            this.dataForm.id = id || 0; // 如果有id就是编辑或者查看,没有id就是新增
            this.visible = true; // 打开弹窗
            this.isDetail = isDetail || false; // isDetail为true就是详情,没有isDetail就是false为编辑
            this.$nextTick(() => {
              this.$refs['elForm'].resetFields(); // 清空表单
              // 如果有id就是编辑查看,这里的请求用于做数据回填
              if (this.dataForm.id) {
                request({
                  url: '/api/System/riskPlan/' + this.dataForm.id, // 根据项目接口写url
                  method: 'get'
                }).then(res =>{
                  this.dataForm = res.data; // 数据回填
                  this.total = this.fxdszArr.length // 总条数
                })
              }
            })
          },
        },
    
      }
    </script>

     

  • 13
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
好的,以下是一个使用 VueElement-UI 实现的亚运会倒计时: 1. 首先,需要安装 VueElement-UI: ```bash npm install vue npm install element-ui ``` 2. 在 Vue 组件中引入 Element-UI 的倒计时组件和样式: ```vue <template> <div class="countdown"> <el-countdown :time="countdown" :auto-start="false" @finish="handleFinish"> <span slot="days">{{ days }} 天</span> <span slot="hours">{{ hours }} 时</span> <span slot="minutes">{{ minutes }} 分</span> <span slot="seconds">{{ seconds }} 秒</span> </el-countdown> </div> </template> <script> import { ElCountdown } from 'element-ui' export default { components: { ElCountdown }, data() { return { countdown: 0 } }, computed: { days() { return Math.floor(this.countdown / (24 * 60 * 60 * 1000)) }, hours() { return Math.floor((this.countdown % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)) }, minutes() { return Math.floor((this.countdown % (60 * 60 * 1000)) / (60 * 1000)) }, seconds() { return Math.floor((this.countdown % (60 * 1000)) / 1000) } }, methods: { startCountdown() { const endDate = new Date('2022-09-10T00:00:00.000Z') const now = new Date() this.countdown = endDate - now }, handleFinish() { console.log('倒计时结束') } }, mounted() { this.startCountdown() } } </script> <style> .countdown { display: flex; justify-content: center; align-items: center; height: 100vh; font-size: 24px; } </style> ``` 3. 在组件中定义一个倒计时的结束时间(即亚运会的开幕时间),并使用计算属性将倒计时的毫秒数转换为天、小时、分钟和秒。 4. 在组件的 mounted 钩子函数中调用 startCountdown 方法,该方法会计算倒计时的毫秒数并将其赋值给 countdown 变量。 5. 最后,将倒计时组件添加到模板中,并设置好样式即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值