iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >vue中的slot封装组件弹窗怎么实现
  • 377
分享到

vue中的slot封装组件弹窗怎么实现

2023-06-30 16:06:33 377人浏览 独家记忆
摘要

这篇文章主要介绍了Vue中的slot封装组件弹窗怎么实现的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中的slot封装组件弹窗怎么实现文章都会有所收获,下面我们一起来看看吧。slot封装组件弹窗<t

这篇文章主要介绍了Vue中的slot封装组件弹窗怎么实现的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中的slot封装组件弹窗怎么实现文章都会有所收获,下面我们一起来看看吧。

slot封装组件弹窗

<template>  <el-dialog :title="title" :visible.sync="dialogVisible" :width="width" center>    <slot name="content"></slot>  </el-dialog></template>
<script>export default {  props: ["title", "width", "dialogVisible"],  data() {    return {};  }};</script>
<style lang="less">.el-dialog__header {  padding: 20px 20px 10px;  display: none;}.el-dialog__body {  padding: 0px !important;}</style>
 <!-- 弹窗 -->        <DialogModal :width="'552px'" :title="'加入黑名单'" :dialogVisible="centerDialogVisible">          <div slot="content" class="popup">            <div class="head">              加入黑名单              <i class="el-icon-close" @click="handelCloseModal()"></i>            </div>            <p class="isAdd">确定要讲客户王佳琛加入甄别黑名单?</p>            <div class="confirm">              <el-button type="primary">确定</el-button>              <el-button plain>取消</el-button>            </div>          </div>        </DialogModal>         <!-- 弹窗 -->

vue组件slot入门---弹窗组件

slot 即插槽,相当于在子组件的 DOM 中留一个位置,父组件如果有需要,就可以在插槽里添加内容。

插槽的基础使用

这里是一个插槽的简单用法。

1.在子组件 Modal.vue 中用 slot 标签预留一个位置,slot 标签中的内容是后备内容,也可以为空:

<div class="modal-content">  <slot>这是个弹框</slot>  <div class="footer">    <button @click="close">close</button>    <button @click="confirm">confirm</button>  </div></div>

后备内容:当父组件不在插槽里添加内容时,插槽显示的内容。

2.在父组件中使用子组件

在父组件中使用子组件,但不向自定义组件的插槽 slot 中添加内容:

<Modal :visible.sync="visible"></Modal>

此时如果打开弹框,弹框中显示的是后备内容“这是个弹框”:

vue中的slot封装组件弹窗怎么实现

在父组件中使用子组件,并给插槽加入个性化内容:

<Modal :visible.sync="visible">个性化内容</Modal>

此时如果打开弹框,弹框中显示的是“个性化内容”:

vue中的slot封装组件弹窗怎么实现

弹窗组件

父App.vue

<template>  <div id="app">    <button @click="visible = true" class="btn">打开“留言”弹框</button>    <button @click="visibleApply = true" class="btn">打开“成为大牛”弹框</button>    <!-- “留言”弹框 -->    <Modal      customClassName="textarea-modal"      title="留言"      :visible.sync="visible"      @confirm="confirm"    >      <template>        <div class="txt">留下你想告诉我们的话...</div>        <textarea          name=""          id=""          cols="30"          rows="10"          placeholder="请写下您的宝贵意见"        ></textarea>      </template>    </Modal>    <!-- “成为大牛”弹框 -->    <Modal      customClassName="apply-modal"      title="成为大牛"      :visible.sync="visibleApply"      @confirm="confirm"    >      <template>        <div class="txt">留下联系方式,立即成为大牛</div>        <div class="mobile">          <input type="text" placeholder="请输入您的手机号码" />        </div>        <div class="code">          <input type="text" placeholder="请输入验证码" />          <button class="btn-code">获取验证码</button>        </div>      </template>    </Modal>  </div></template>
<script>// 引入组件import Modal from './components/Modal.vue';export default {  name: 'app',  // 注册组件  components: {    Modal  },  data: function() {    return {      // 控制“留言”弹框      visible: false,      // 控制“成为大牛”弹框      visibleApply: false    };  },  methods: {    // 自定义函数 confirm    confirm() {      // todo    }  }};</script>
<style lang="sCSS">#app {  font-family: 'Avenir', Helvetica, Arial, sans-serif;  -WEBkit-font-smoothing: antialiased;  -moz-osx-font-smoothing: grayscale;  text-align: center;  color: #2c3e50;  margin-top: 60px;}.btn {  width: fit-content;  height: 40px;  font-size: 15px;  line-height: 40px;  box-sizing: border-box;  cursor: pointer;  border: none;  background: #ffffff;  border: 1px solid #ebebeb;  color: #1b1b1b;  padding: 0 20px;  margin-right: 20px;  &:focus {    outline: none;  }}.textarea-modal {  .txt {    text-align: left;    padding-top: 20px;    font-size: 16px;    line-height: 22px;    color: #000000;  }  textarea {    width: 355px;    height: 110px;    border: 1px solid #e6e6e6;    font-size: 16px;    line-height: 22px;    color: #000000;    padding: 14px 20px;    box-sizing: border-box;    margin-top: 18px;    &::placeholder {      color: rgba(0, 0, 0, 0.2);    }    &:focus {      outline: none;    }  }}.apply-modal {  .txt {    text-align: left;    padding-top: 20px;    font-size: 16px;    line-height: 22px;    color: #000000;    margin-bottom: 18px;  }  .mobile input,  .code input {    width: 355px;    height: 50px;    background: #ffffff;    border: 1px solid #eeeeee;    font-size: 16px;    color: #000000;    padding: 14px 20px;    box-sizing: border-box;    &::placeholder {      color: rgba(0, 0, 0, 0.2);    }    &:focus {      outline: none;    }  }  .code {    margin-top: 20px;    position: relative;    input {      padding-right: 120px;    }    .btn-code {      height: 50px;      padding: 0 20px;      font-size: 14px;      line-height: 50px;      color: #2c3744;      background: none;      border: none;      position: absolute;      top: 0;      right: 0;      &:focus {        outline: none;      }      &::before {        content: '';        display: block;        width: 1px;        height: 20px;        background: #e5e5e5;        position: absolute;        left: 0;        top: 15px;      }    }  }}</style>

子Modal.vue

<template>  <div :class="['modal', customClassName]" v-if="visible">    <div class="modal-content">      <div class="modal-header">        <div class="title">{{title}}</div>        <button class="btn-close" @click="close"></button>      </div>      <div class="modal-body">        <slot></slot>      </div>      <div class="modal-footer">        <button class="btn-close" @click="close">取消</button>        <button class="btn-confirm" @click="confirm">提交</button>      </div>    </div>  </div></template>
<script>export default {  name: 'Modal',  // customClassName 为自定义类名  // title 为弹框标题  props: ['visible', 'title', 'customClassName'],  methods: {    close() {      this.$emit('update:visible', false);    },    confirm() {      console.log('confirm');      this.close();    }  }};</script>
<style lang="scss" scoped>.modal {  position: fixed;  top: 0;  bottom: 0;  left: 0;  right: 0;  background: rgba(#000, 0.5);  display: flex;  align-items: center;  justify-content: center;  .modal-content {    width: 415px;    background: #fff;    border-radius: 12px;    text-align: center;    .modal-header {      height: 65px;      position: relative;      font-weight: 500;      font-size: 18px;      line-height: 65px;      color: #000000;      border-bottom: 1px solid #f2f2f2;      .btn-close {        width: 16px;        height: 16px;        background: url(https://qgt-document.oss-cn-beijing.aliyuncs.com/P3-5-Vue/5/5-1-1.png)          no-repeat center / contain;        position: absolute;        top: 23px;        right: 30px;        border: none;        cursor: pointer;        &:focus {          outline: none;        }      }    }    .modal-body {      padding: 0 30px;      font-size: 0;    }    .modal-footer {      padding: 30px;      display: flex;      justify-content: space-between;      .btn-close,      .btn-confirm {        width: 125px;        height: 40px;        font-size: 15px;        line-height: 40px;        box-sizing: border-box;        cursor: pointer;        border: none;        &:focus {          outline: none;        }      }      .btn-close {        background: #ffffff;        border: 1px solid #ebebeb;        color: #1b1b1b;      }      .btn-confirm {        background: #3ab599;        color: #fff;      }    }  }}</style>

关于“vue中的slot封装组件弹窗怎么实现”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“vue中的slot封装组件弹窗怎么实现”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程网精选频道。

--结束END--

本文标题: vue中的slot封装组件弹窗怎么实现

本文链接: https://www.lsjlt.com/news/330339.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • vue中的slot封装组件弹窗怎么实现
    这篇文章主要介绍了vue中的slot封装组件弹窗怎么实现的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中的slot封装组件弹窗怎么实现文章都会有所收获,下面我们一起来看看吧。slot封装组件弹窗<t...
    99+
    2023-06-30
  • vue中的slot封装组件弹窗
    目录slot封装组件弹窗vue组件slot入门---弹窗组件插槽的基础使用弹窗组件slot封装组件弹窗 <template>   <el-dialog :title...
    99+
    2024-04-02
  • vue extend+promise封装全局弹窗组件
    本文实例为大家分享了vue extend+promise封装全局弹窗组件的具体代码,供大家参考,具体内容如下 因为项目没有引入第三方UI库,所以所有的公共组件都需要自己封装现在需要一...
    99+
    2024-04-02
  • vue中怎么实现一个toast弹窗组件
    本篇文章给大家分享的是有关vue中怎么实现一个toast弹窗组件,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。首先,我们来分析一下弹窗组件的特...
    99+
    2024-04-02
  • Vue组件封装怎么实现
    这篇文章主要介绍“Vue组件封装怎么实现”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Vue组件封装怎么实现”文章能帮助大家解决问题。一、组件封装的优势复用性:组件封装可以将常用的功能或视图模块抽象...
    99+
    2023-07-05
  • Vue弹窗组件的实现方法
    本文实例为大家分享了Vue弹窗组件的实现具体代码,供大家参考,具体内容如下 弹窗组件包含内容: 弹窗遮罩层内容层的实现(涉及slot、props、$on、$emit) 实现步骤: 1...
    99+
    2024-04-02
  • 怎么封装一个vue中也可使用的uniapp全局弹窗组件
    这篇文章主要介绍了怎么封装一个vue中也可使用的uniapp全局弹窗组件的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇怎么封装一个vue中也可使用的uniapp全局弹窗组件文章都会有所收获,下面我们一起来看看吧...
    99+
    2023-07-05
  • vue中怎么封装一个弹出框组件
    这期内容当中小编将会给大家带来有关vue中怎么封装一个弹出框组件,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1.你需要先建一个弹出框的模板://首先创建一个mack.v...
    99+
    2024-04-02
  • vue弹窗组件怎么用
    这篇文章主要为大家展示了“vue弹窗组件怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“vue弹窗组件怎么用”这篇文章吧。具体...
    99+
    2024-04-02
  • vue中怎么实现一个弹窗插件
    vue中怎么实现一个弹窗插件,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。popup.vue<template>  ...
    99+
    2024-04-02
  • Vue基于Element-ui怎么实现表格弹窗组件
    本篇内容主要讲解“Vue基于Element-ui怎么实现表格弹窗组件”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Vue基于Element-ui怎么实现表格弹窗组件”吧!效果图使用方式acTab...
    99+
    2023-06-30
  • vue弹窗消息组件怎么用
    这篇文章主要介绍vue弹窗消息组件怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!本来打算写一个那种提示完了自动消失的弹窗的,但是没有想好淡入淡出的效果。所以暂时算是半成品。练习...
    99+
    2024-04-02
  • VB.NET中怎么实现组件封装
    这篇文章给大家介绍VB.NET中怎么实现组件封装,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。新建一个项目,选择Visual Basic \ Window \ 类库,假设项目名为ClassLibrary1然后 在sol...
    99+
    2023-06-17
  • vue组件化中slot怎么用
    这篇文章将为大家详细讲解有关vue组件化中slot怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。前言slot可以在子组件中开启插槽,在父组件引用该组建时,可以定义这...
    99+
    2024-04-02
  • 详解Vue全局组件的挂载之实现弹窗组件
    目录vue组件挂载类型组件挂载代码示例1.vue.extend()方法2.render函数挂载vue组件挂载类型 vue中组件的挂载分为两种类型: vue.extend() rend...
    99+
    2022-11-13
    Vue组件挂载 弹窗 Vue组件挂载 Vue弹窗组件 Vue 弹窗
  • Vue实现轮播图组件的封装
    目录轮播图功能-获取数据轮播图-通用轮播图组件轮播图-数据渲染轮播图-逻辑封装轮播图功能-获取数据 目标: 基于pinia获取轮播图数据 核心代码: (1)在types/data.d...
    99+
    2023-05-16
    Vue轮播图组件封装 Vue组件封装
  • Vue基于Element-ui实现表格弹窗组件
    本文实例为大家分享了Vue基于Element-ui实现表格弹窗组件的具体代码,供大家参考,具体内容如下 效果图 使用方式 acTable1 () {   this.$modalTa...
    99+
    2024-04-02
  • vue组件中slot插口怎么用
    这篇文章主要介绍vue组件中slot插口怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!子组件<template>   <div ...
    99+
    2024-04-02
  • Vue中怎么对ElementUI的Dialog组件封装
    本篇内容主要讲解“Vue中怎么对ElementUI的Dialog组件封装”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Vue中怎么对ElementUI的Dialog组件封装”吧!对Element...
    99+
    2023-07-05
  • 如何使用vue实现一个toast弹窗组件
    本篇内容介绍了“如何使用vue实现一个toast弹窗组件”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!首先,我们来分析一下弹窗组件的特性(需...
    99+
    2023-07-04
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作