使用<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="paragraph-info"> <!-- 显示段落内容 --> <div class="header"> <el-button text type="danger" @click="state.clearAll">一键清空</el-button> <span>共计:</span> <b>{{ state.data.length }}</b> </div> <div class="box"> <template v-if="state.data.length > 0"> <div class="item" v-for="(i, k) in state.data" :key="k"> <div class="tp"> <div class="tt"> {{ i.title }} </div> <div class="act"> <el-button size="small" type="primary" text @click="state.open(i)" >编辑</el-button > <el-button size="small" type="danger" text @click="state.del(i)" >删除</el-button > </div> </div> <div class="cnt"> <div v-html="i.content"></div> </div> </div> </template> <template v-else> <div class="no-data">点击下方“增段落”按钮增。</div> </template> </div> <div class="plus-btn" @click="state.open()">增段落</div> </div> <!-- 增窗口 --> <el-dialog v-model="state.dialog" append-to-body :close-on-click-modal="false" destroy-on-close width="996px" top="5%" > <template #header> <slot>信息更</slot> </template> <el-card> <el-form :model="state.form" ref="formRef" label-position="top" :rules="state.rules" > <el-form-item label="标题" prop="title"> <el-input placeholder="请输入标题" v-model.number="state.form.title" ></el-input> </el-form-item> <el-form-item label="内容" prop="content"> <self-editor v-model="state.form.content"></self-editor> </el-form-item> </el-form> </el-card> <template #footer> <el-button type="primary" @click="state.handler()"> 保存 </el-button> <el-button @click="state.dialog = false">关闭</el-button> </template> </el-dialog> </template>
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值