使用<el_button>打开一个新的VUE组件

引入VUE组件

import 自定义名 from '路径'

注册组件

export default {

  components: {
      自定义名
  },
}

在HTML部分定义组件

<template>

<组件名 ref=dialog v-on:loadData="loadData"></组件名>
</template>
 <el-button type="text" @click="dialog">打开组件
      <组件名></组件名>
  </el-button>

JS部分

  dialog() {
                console.log("击中")
              this.$refs.elDialog.init();
 },

注意的是,this.$ref.要与HTML部分组件定义的ref绑定一致

相较于原生JS VUE提供的this.$refs要更节省dom节点的消耗

不过逻辑都在于渲染dom树

<template> <div class="app-container"> <!-- 操作工具栏 --> <div class="mb-4"> <el-button type="primary" @click="showFormDialog()">新增分类</el-button> </div> <!-- 树形表格 --> <el-table :data="tableData" row-key="id" :tree-props="{children: 'children'}" border style="width: 100%" > <el-table-column prop="id" label="ID" width="80"> <template #default=“{ row }”> <template v-if=“row.children && row.children.length > 0”> {{ row.id }} </template> <span v-else class=“empty-id”></span> </template> </el-table-column> <el-table-column prop=“title” label=“分类名称” /> <el-table-column label=“操作” width=“180” align=“center”> <template #default=“{ row }”> <el-button type=“primary” size=“small” @click=“showFormDialog(row.id)” >修改</el-button> <el-button type=“danger” size=“small” @click=“handleDelete(row.id)” >删除</el-button> </template> </el-table-column> </el-table> <!-- 表单对话框 --> <el-dialog v-model="formVisible" :title="currentId ? '修改分类' : '新增分类'" width="30%" > <el-form ref="formRef" :model="form" :rules="rules" label-width="80px" > <el-form-item label="分类名称" prop="title"> <el-input v-model="form.title" placeholder="请输入分类名称" /> </el-form-item> </el-form> <template #footer> <el-button @click="formVisible = false">取消</el-button> <el-button type="primary" @click="submitForm">确认</el-button> </template> </el-dialog> </div> </template>要求点击新增分类时弹出的对话框里再加一个上级选择,用select树形结构数据展示,给出vue3的全部代码
03-22
<template> <div> <div> <!--搜索栏--> <el-input v-model="name" placeholder="请输入菜单名称" style="width: 200px" prefix-icon="el-icon-user"></el-input> <el-button class="el-icon-search" style="margin-left: 10px" type="primary" @click="load">查询</el-button> <el-button class="el-icon-refresh" style="margin-left: 10px" type="warning" @click="reset">重置</el-button> </div> <div style="margin-top: 20px;margin-bottom:35px;"> <!-- 新增、批量删除 --> <el-button class="el-icon-plus" style="margin-right: 10px" type="success" @click="save(null)">新增</el-button> <el-button class="el-icon-close" style="margin-left: 10px" type="danger" @click="deleteByids" >批量删除</el-button> </div> <el-table :data="tableData" border stripe :header-cell-style="getRowClass" @selection-change="handleSelectionChange" row-key="id" border default-expand-all> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="id" label="id"></el-table-column> <el-table-column prop="name" label="菜单名称"></el-table-column> <el-table-column prop="path" label="菜单路径"></el-table-column> <el-table-column prop="icon" label="菜单图标"> <template v-slot:default="scope"> <i :class="scope.row.icon"></i> </template> </el-table-column> <el-table-column prop="pagePath" label="页面路径"></el-table-column> <el-table-column prop="description" label="菜单描述"></el-table-column> <el-table-column prop="sortNum" label="排序"></el-table-column> <el-table-column label="操作" width="300"> <template v-slot="scope"> <div class="action-buttons"> <!-- 添加容器方便布局 --> <el-button type="success" size="mini" class="compact-btn" @click="save(scope.row.id)" v-if="!scope.row.pid && !scope.row.path">新增子菜单</el-button> <el-button type="prima
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值