avue或者vue子组件数据变化后刷新父组件

本文详细介绍了如何在使用Avue表单设计器时,通过子组件操作触发父组件数据的刷新,包括两种方法:直接在父组件中定义刷新方法和通过子组件的自定义事件更新父组件。涉及到了Vue组件间的通信和数据同步技巧。

关注Avue表单设计器的使用: 【Avue表单设计器的使用技巧】

关注Avue企业级开发应用官方源代码: 官方源代码

 

描述:  使用avue.js或者vue.js做后台管理系统时,常常涉及到子组件(子弹窗) 修改,添加操作后,需要刷新父组件重新加载数据:

           父组件代码:  重点关注该方法:

           父组件中定义该方法:

 handleRefreshChange() {
      this.getList(this.page);  // 父组件获取后台的数据
 }
<template>
  <div class="user">
    <basic-container>
      <avue-crud
        :option="option"
        ref="crud"
        v-model="form"
        :page="page"
        @on-load="getList"
        @size-change="sizeChange"
        @current-change="currentChange"
        :table-loading="listLoading"
        @search-change="handleFilter"
        @refresh-change="handleRefreshChange"
        @row-update="update"
        @row-save="create"
        :before-open="handleOpenBefore"
        :data="list"
      >
        <template slot="username" slot-scope="scope">
          <span>{
  
  { scope.row.username }}</span>
        </template>
        <template slot="amount" slot-scope="scope">
          <div v-if="scope.row.currType === 'VIR'">
            {
  
  { scope.row.amount }}
          </div>
          <div v-if="scope.row.currType !== 'VIR'">
            {
  
  { scope.row.amount / 100 }}
          </div>
        </template>

        <template slot="role" slot-scope="scope">
          <span v-for="(role, index) in scope.row.roleList" :key="index">
            <el-tag>{
  
  { role.roleName }} </el-tag>&nbsp;&nbsp;
          </span>
        </template>
        <template slot="deptId" slot-scope="scope">
          {
  
  { scope.row.deptName }}
        </template>
        <template slot="lockFlag" slot-scope="scope">
          <el-tag>{
  
  { scope.label }}</el-tag>
        </template>
        <template slot="menu" slot-scope="scope">
          <el-button v-show = "scope.row.status == 100 || scope.row.status == 110"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row, scope.index)">冲账
          </el-button>
          <el-button  v-show = "scope.row.status === -100"
            type="text"
            icon="el-icon-edit"
            @click="handlePushItem(scope.row, scope.index)">重新记账
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
    <info-view v-if="infoVisible" ref="infoView"></info-view>
  </div>
</template>

<script>
import { fetchList, putObj, putObjStatus } from "@/api/acct/acctTradeRecord";
import { deptRoleList } from "@/api/admin/role";
import { fetchTree } from "@/api/admin/dept";
import { tableOption } from "@/const/crud/acct/acctTradeRecord";
import InfoView from "./record-form";
import { mapGetters } from "vuex";

export default {
  name: "table_user",
  components: {
    InfoView,
  },
// data()函数返回对象 : {}
  data() {
    return {
      option: tableOption,
      treeDeptData: [],
      checkedKeys: [],
      roleProps: {  // 配置项传递数据
        label: "roleName",
        value: "roleId",
      },
      defaultProps: {
        label: "name",
        value: "id",
      },
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10, // 每页显示多少条,
        isAsc: false, //是否倒序
      },
      searchParam: {},
      list: [],
      listLoading: true,
      role: [],
      form: {},  // 配置项key,value为一个空对象,相当于先声明一个变量,并初始化一个空对象
      rolesOptions: [],
      infoVisible: false,
    };
  },
  computed: {
    ...mapGetters(["permissions"])
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值