vue自定义弹出询问框、输入框、提示框(附源码及演示视频)

这篇具有很好参考价值的文章主要介绍了vue自定义弹出询问框、输入框、提示框(附源码及演示视频)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

涉及技术点

遮罩层样式,自定义组件,子组件套用组件,子组件调用父组件方法,组件属性监听,输入框默认获得焦点,输入框数据双向绑定

效果图

询问框:

vue弹出提示框,vue.js,vue.js,Powered by 金山文档

输入框:

vue弹出提示框,vue.js,vue.js,Powered by 金山文档

提示框

vue弹出提示框,vue.js,vue.js,Powered by 金山文档
询问框组件代码
<template>
  <div v-if="show" class="mask">
    <div class="dlg-msg-box flex flex-col">
      <div class="flex flex-space-between full-width">
        <div class="font-bold">{{caption}}</div>
        <div class="pointer" @click="close"><img class="logo-22" src="@/assets/images/guanbi.png"/></div>
      </div>
      <div class="margin-top-l" style="height:45px;">{{msg}}</div>
      <div class="flex flex-end margin-top-xl">
        <div class="btn-huibai-auto pointer" style="width:80px" @click="cancelClick">取消</div>
        <div class="margin-left-m btn-blue-auto pointer" style="width:80px" @click="confirmClick">确定</div>
      </div>
    </div>
  </div>
</template>
 
<script>


export default {
    name: 'MsgBox',//组件递归必须有name属性 不然无法递归    
    props: {
        caption:{},
        show: {},
        msg:{},
    },
    data() {
        return {
        }
    },

    methods: {
        close() {
            this.$emit('close');
        },
        confirmClick() {
            this.$emit('confirm');
        },
        cancelClick() {           
            this.$emit('cancel');
        }

    }
}
</script>

<style>
    .dlg-msg-box {
        border-radius: 5px;
        width: 350px;
        height: 160px;
        background-color: #fff;
        padding: 30px;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
    }
</style>

输入框组件代码
<template>
    <div v-if="show" class="mask">
      <div class="dlg-input-box flex flex-col">
        <div class="flex flex-space-between full-width">
          <div class="font-bold">{{caption}}</div>
          <div class="pointer" @click="close"><img class="logo-22" src="@/assets/images/guanbi.png"/></div>
        </div>
        <div class="margin-top-xl flex flex-col">
            <input class="input-box" placeholder="请输入" v-model="inputValue" ref="getfocus"/>
        </div>
        <div class="flex flex-end margin-top-xl">
          <div class="btn-huibai-auto pointer" style="width:80px" @click="cancelClick">取消</div>
          <div class="margin-left-m btn-blue-auto pointer" style="width:80px" @click="confirmClick">确定</div>
        </div>
      </div>
      <msg-show caption="提示" :msg="msgText" :show="showMessage" @close="showMessage=false"></msg-show>    
    </div>
  </template>
   
  <script>
  
  import MsgShow from '@/components/MsgShow' 

  export default {
      name: 'InputBox',//组件递归必须有name属性 不然无法递归    
      props: {
          caption:{},
          value:{},
          show: {},
      },
      components: {
        MsgShow
      },
      watch: {
        show(val){
            if (val == true) {
                this.$nextTick(() => {
                    this.$refs.getfocus.focus();
                })
            }
        },
        value(val){
          this.inputValue = val;
        }

      },
      data() {
          return {
            showMessage:false,
            inputValue:'',
            msgText:''
          }
      },
      
      methods: {
       
          close() {
            this.$emit('close');
          },
          confirmClick() {
            if (this.inputValue == "") {
                this.msgText = "内容未填写";
                this.showMessage = true;
            } else {
                this.$emit('confirm', this.inputValue);
            }
            
          },
          cancelClick() {           
            this.$emit('cancel');
          }
  
      }
  }
  </script>
  
  <style>
      .dlg-input-box {
          border-radius: 5px;
          width: 350px;
          height: 160px;
          background-color: #fff;
          padding: 30px;
          position: absolute;
          top: 0;
          bottom: 0;
          left: 0;
          right: 0;
          margin: auto;
      }
  </style>
  
提示框组件代码
<template>
    <div v-if="show" class="mask">
      <div class="dlg-show flex flex-col">
        <div class="flex flex-space-between full-width">
          <div class="font-bold">{{caption}}</div>
          <div class="pointer" @click="close"><img class="logo-22" src="@/assets/images/guanbi.png"/></div>
        </div>
        <div class="margin-top-l" style="height:45px;">{{msg}}</div>
        <div class="flex flex-end margin-top-xl">
          <div class="margin-left-m btn-blue-auto pointer full-width" @click="confirmClick">确定</div>
        </div>
      </div>
    </div>
  </template>
   
  <script>
  
  export default {
      name: 'MsgShow',//组件递归必须有name属性 不然无法递归    
      props: {
          caption:{},
          show: {},
          msg:{},
      },
      data() {
          return {
          }
      },
  
      methods: {
          close() {
              this.$emit('close');
          },
          confirmClick() {
              this.$emit('close');
          }
      }
  }
  </script>
  
  <style>
      .dlg-show {
          border-radius: 5px;
          width: 300px;
          height: 140px;
          background-color: #fff;
          padding: 30px;
          position: absolute;
          top: 0;
          bottom: 0;
          left: 0;
          right: 0;
          margin: auto;
      }
  </style>
  
父组件代码
<template>
    <div class="body">
      <div class="table">
        <div class="filter font-bold">vue自定义弹出询问框、输入框、提示框</div>
        <div class="padding-left-l padding-right-l">

          <div class="pointer cannotselect margin-top-l margin-left-l btn-blue-full" @click="MsgBoxClick">询问框</div>
          <div class="pointer cannotselect margin-top-l margin-left-l btn-blue-full" @click="InputBoxClick">输入框</div>
          <div class="pointer cannotselect margin-top-l margin-left-l btn-blue-full" @click="MsgShowClick">提示框</div>

          <msg-box :caption="caption" :msg="msgText" :show="showMsgBox" @close="showMsgBox=false"  @confirm="MsgBoxYes" @cancel="showMsgBox=false">
          </msg-box>
          <msg-show :caption="caption" :msg="msgText" :show="showMsgShow" @close="showMsgShow=false">
          </msg-show>    
          <input-box :caption="caption" :show="showInput" :value="inputValue" @close="showInput=false" @confirm="inputBoxYes" @cancel="showInput=false">
          </input-box>
        </div>  

      </div>
    </div>
</template>

<script>
/*
       名称:vue自定义弹出询问框、输入框、提示框
       功能:自定义属于自己的弹出窗,涉及到技术点:遮罩层样式,自定义组件,子组件套用组件,子组件调用父组件方法,组件属性监听,输入框默认获得焦点,输入框数据双向绑定        
       作者:唐赢   
       时间:2023-1-17
*/
  import InputBox from '@/components/InputBox' 
  import MsgBox from '@/components/MsgBox' 
  import MsgShow from '@/components/MsgShow' 

  export default {
    name: 'Main',
    components: {
      InputBox,MsgBox,MsgShow
    },
    data () {
      return {

        inputValue:'',
        caption: '',
        msgText: '',       
        showMsgBox : false,
        showMsgShow: false,
        showInput: false,
        
      }
    },
    methods: {
      MsgBoxClick() {
        this.caption = "询问";
        this.msgText = "确定要删除该条记录吗?"
        this.showMsgBox = true;
      },
      InputBoxClick() {
        this.caption = "请输入";
        this.inputValue = "工作";
        this.showInput = true;
      },     
      MsgShowClick() {
        this.caption = "提示";
        this.msgText = "操作完毕!";
        this.showMsgShow = true;
      },
      MsgBoxYes(){
        this.showMsgBox = false;
        this.caption = "提示";
        this.msgText = "您选择了确定操作";
        this.showMsgShow = true;
      },
      inputBoxYes(value){
        console.log(value);
        this.showInput = false;

        this.caption = "提示";
        this.msgText = "您输入的值是【" + value + "】";
        this.showMsgShow = true;


      }
    },

    
  }
</script>

  <!-- Add "scoped" attribute to limit CSS to this component only -->
  <style scoped>
  .body {
    display: flex;
    justify-content: center;
    margin-top: 73px;
    width: 100%;    
  }
  .table {
    background-color: #fff;
    width: 1080px;
    min-height: 800px;
    box-shadow: 0px 3px 6px rgba(0, 0, 0, .1);
    margin-bottom: 10px;
  }
  .filter {
    display: flex;
    height: 60px;
    align-items:center;
    background-color: #fff;
    font-size: 18px;
    justify-content: center;
    border-bottom: 1px solid rgba(0, 0, 0, .2);;
  }


  </style>
  
下载及演示

操作演示地址:https://lusun.com/v/Szth3xngrsH

源码地址:https://download.csdn.net/download/gdgztt/87389680文章来源地址https://www.toymoban.com/news/detail-515879.html

到了这里,关于vue自定义弹出询问框、输入框、提示框(附源码及演示视频)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Prism框架自定义弹出提示窗

      1、App.xaml.cs 2、弹出界面布局xaml 3 、弹窗model 引用IDialogAware 接口 4、调用 总结:其中要注意的是请先理解prism框架 IDialogService 服务和IDialogAware接口的使用 附上:prism框架的示例Demo github.com/PrismLibrary/Prism-Samples-Wpf

    2024年02月16日
    浏览(24)
  • layui框架学习(25:弹出层模块_加载框&询问框)

      layui框架的弹出层模块layer中最重要的函数即layer.open,基于该函数,layer模块封装了很多常用弹出框,上文已介绍了消息框和提示框函数,本文学习加载框和询问框函数的基本用法,同时继续学习layer模块中基础参数的用法。   加载框函数的形式为layer.load(icon, options) ,

    2024年02月07日
    浏览(34)
  • Web 自动化测试案例——关闭某视频网站弹出广告以及打开登录框输入内容

    人生苦短,我用Python。许久没写博客了,今天又是久违的参与话题的讨论,话题的内容是: 如何入门 Python 的? 这个话题对于我来说有点小尴尬,因为我没有系统的学习过 Python 这门语言,只不过在写些算法题、小demo接触过,还有就是帮朋友搞大数据作业时(爬取数据、分析

    2024年02月10日
    浏览(64)
  • Web 自动化测试案例(入门级)——关闭某视频网站弹出广告以及打开登录框输入内容

    人生苦短,我用Python。许久没写博客了,今天又是久违的参与话题的讨论,话题的内容是: 如何入门 Python 的? 这个话题对于我来说有点小尴尬,因为我没有系统的学习过 Python 这门语言,只不过在写些算法题、小demo接触过,还有就是帮朋友搞大数据作业时(爬取数据、分析

    2024年02月06日
    浏览(54)
  • 萝卜视频源码前后端影视APP源码/更换播放内核到3.2.6/带视频演示

    🎈 限时活动领体验会员:可下载程序+网创项目+短视频素材 🎈 ☑️ 品牌:萝卜视频 ☑️ 语言:PHP ☑️ 类型:影视 ☑️ 支持:APP 🎉 有需要的朋友记得关+赞+评,免费分享需要的文章底部获取!!! 🎉 ✨ 源码介绍 萝卜视频源码前后端,更换播放内核到3.2.6,原版3.0.

    2024年02月15日
    浏览(25)
  • 【提示工程】询问GPT返回Json结构数据

    众所周知,我们可以通过构建的Prompt获取期望的内容,但是通常都是以自然语言返回的,假如我们想得到结构化的数据,比如Json,XML那么怎么办,这篇文章给你一个思路。 要实现询问大模型后返回结构化的数据,首先能想到的是可以通过在提示末尾添加以 JSON 格式提供您的

    2024年02月09日
    浏览(25)
  • 询问ChatGPT的高质量答案艺术——提示工程指南

    书籍笔记《The Art of Asking ChatGPT for High-Quality Answers: A complete Guide to Prompt Engineering Techniques》 注意:由于chatGPT回复字数限制,凡是在案例中涉及到长文本的不会截图 提示工程是创建提示、询问或指令的过程,用以指导像ChatGPT这样的语言模型的输出。它允许用户控制模型的输出

    2024年02月03日
    浏览(73)
  • 三子棋游戏----C语言版【超级详细 + 视频演示 + 完整源码】

    ㊙️小明博客主页:➡️ 敲键盘的小明 ㊙️ ✅关注小明了解更多知识☝️ 提示:本篇文章为C语言版的三子棋小游戏的制作,内含超详细讲解和完整源码,以及视频演示,内容如若有误,请联系小明及时更正。 转载请注明原创,谢谢。 提示:以下是本篇文章正文内容:  

    2024年04月14日
    浏览(28)
  • vue2 el-table行悬停时弹出提示信息el-popover

    实现方法,用到了cell-mouse-enter、cell-mouse-leave两个事件,然后在表格的首列字段中,加个el-popover组件,当然你也可以选择在其他字段的位置来显示提示框,看自己的需求了。 示例代码: 在enter方法中,还可以根据row行数据进行一些处理,比如根据状态status来判断是否弹出提示

    2024年01月18日
    浏览(58)
  • vue前端实现图片下载,实现点击按钮弹出本地窗口,选择自定义保存路径

    直接上代码,废话不多说,点关注,不迷路 一、下载代码 二、别找代码了,不用代码就可以实现 以下按照步骤一步一步来 按照红色箭头所指,用鼠标戳它 恭喜你,功能完成了

    2024年02月13日
    浏览(42)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包