运用的知识点包括:

路由的配置

插槽

vue的过渡动画

路由重定向

router/index.js里面配置路由

  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import Home from '@/components/home'
  4. import About from '@/components/about'
  5.  
  6. Vue.use(Router)
  7.  
  8. export default new Router({
  9. mode:'history',
  10. routes: [
  11. {
  12. path: '/home',
  13. name: 'Home',
  14. component: Home
  15. },
  16. {
  17. path: '/about',
  18. name: 'About',
  19. component: About
  20. },
  21. { path: '/', redirect:'/home' }
  22.  
  23. ]
  24. })

app.vue

  1. <template>
  2. <div id="app">
  3. <router-link :to="{path:'/home'}">home</router-link>
  4. <router-link :to="{path:'/about'}">about</router-link>
  5. <router-view/>
  6. </div>
  7. </template>
  8.  
  9. <script>
  10. export default {
  11. name: 'App'
  12. }
  13. </script>
  14.  
  15. <style>
  16. #app {
  17. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  18. -webkit-font-smoothing: antialiased;
  19. -moz-osx-font-smoothing: grayscale;
  20. text-align: center;
  21. color: #2c3e50;
  22. margin-top: 60px;
  23. }
  24. </style>

home.vue

  1. <template>
  2. <div class="home">
  3. <p>{{msg}}</p>
  4. <transition name="slide-fade">
  5. <v-modal v-show="modalStatus" :title="title" :content="content" :btnType="btnType">
  6. <slot>
    <button v-for="item in btnType" :class="item.class" @click="modalStatus=false">
      {{item.vlaue}}
    </button>
  1. </slot>
  2. </v-modal>
  3. </transition>
  4. <button @click="openHomeModal()">打开modal</button>
  5.  
  6. </div>
  7. </template>
  8.  
  9. <script>
  10. import Modal from "@/components/modal.vue";
  11. export default {
  12. name: "HelloWorld",
  13. data() {
  14. return {
  15. msg: "我是首页信息",
  16. modalStatus: false,
  17. title: "我是首页,我骄傲",
  18. content: "我是首页的内容",
        btnType: [{"value":"确定","class":"danger"},{"value": "取消","class":"defalut"}]
  1. };
  2. },
  3. components: {
  4. "v-modal": Modal
  5. },
  6. methods: {
  7. openHomeModal() {
  8. this.modalStatus = true;
  9. }
  10. }
  11. };
  12. </script>
  13.  
  14. <!-- Add "scoped" attribute to limit CSS to this component only -->
  15. <style scoped lang="scss">
  16.  
  17. /* 可以设置不同的进入和离开动画 */
  18. /* 设置持续时间和动画函数 */
  19. .slide-fade-enter-active {
  20. transition: all .3s ease;
  21. }
  22. .slide-fade-leave-active {
  23. transition: all .2s cubic-bezier(1.0, 0.5, 0.8, 1.0);
  24. }
  25. .slide-fade-enter, .slide-fade-leave-to
  26. /* .slide-fade-leave-active for below version 2.1.8 */ {
  27. transform: translateY(-10px);
  28. opacity: 0;
  29. }
  30. </style>

about.vue

  1. <template>
  2. <div class="about">
  3. <p>{{aboutmsg}}</p>
  4. <button @click="openHomeModal()">打开about里面的modal</button>
  5. <transition name="slide-fade">
  6. <v-modal v-show="modalStatus" :title="title" :content="content">
  7.  
  8. <slot>
     <button v-for="item in btnType" :class="item.class" @click="modalStatus=false">
      {{item.vlaue}}
      </button>
  1. </slot>
  2. </v-modal>
  3. </transition>
  4. </div>
  5. </template>
  6. <script>
  7. import Modal from "@/components/modal.vue";
  8. export default {
  9. data() {
  10. return {
  11. modalStatus: false,
  12. aboutmsg: "我是关于页面",
  13. title: "我是关于页面的title",
  14. content: "我是关于页面的内容",
        btnType:["value":"确定","class":"default"]
  15. };
  16. },
  17. methods: {
  18. openHomeModal() {
  19. this.modalStatus = true;
  20. }
  21. },
  22. components: {
  23. "v-modal": Modal
  24. }
  25. };
  26. </script>
  27. <style lang="scss">
  28.  
  29. /* 可以设置不同的进入和离开动画 */
  30. /* 设置持续时间和动画函数 */
  31. .slide-fade-enter-active {
  32. transition: all .3s ease;
  33. }
  34. .slide-fade-leave-active {
  35. transition: all .2s cubic-bezier(1.0, 0.5, 0.8, 1.0);
  36. }
  37. .slide-fade-enter, .slide-fade-leave-to
  38. /* .slide-fade-leave-active for below version 2.1.8 */ {
  39. transform: translateY(-10px); //从上面下移,逐渐出现
  40. opacity: 0;
  41. }
  42. </style>

modal.vue

  1. <template>
  2. <div class="modal">
  3. <div class="header">{{title}}</div>
  4. <div class="content">{{content}}</div>
  5. <div class="footer">
  6. <slot></slot>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. export default{
  12. data(){
  13. return {}
  14. },
  15. props:['title','content'],
  16.  
  17. }
  18. </script>
  19. <style lang="scss">
  20. .modal {
  21. width:500px;
  22. height:400px;
  23. position: absolute;
  24. top:50%;
  25. left:50%;
  26. margin-toP:-250px;
  27. margin-left:-200px;
  28. border:1px solid #666;
  29. .header {
  30. height:60px;
  31. line-height:60px;
  32. text-align: center;
  33. background:#666;
  34. border-bottom: 1px solid #000;
  35. box-sizing: border-box;
  36. }
  37. .content {
  38. background:orange;
  39. height:290px;
  40.  
  41. }
  42. .footer {
  43. height:50px;
  44. line-height: 50px;
  45. button {
  46. vertical-align: middle;
  47. display: inline-block;
  48. width:80px;
  49. height:40px;
  50. line-height: 40px;
  51. color:#fff;
  52. &.danger{
  53. background:red;
  54.  
  55. }
  56. &.default{
  57. background:#ddd;
  58. }
  59.  
  60. }
  61.  
  62. }
  63. }
  64. </style>

做一个vue模态弹出框如何的更多相关文章

  1. 做一个iframe的弹出框

    群里有个人想在微信页面里面加弹出框.作为前端的我,想着不可能这样做.后来一个人说了: A:如果对方没有防盗链的话,你可以建个页面,内置iframe 到他的页面,然后把url 的参数也传入你的ifram ...

  2. Bootstrap模态弹出框

    前面的话 在 Bootstrap 框架中把模态弹出框统一称为 Modal.这种弹出框效果在大多数 Web 网站的交互中都可见.比如点击一个按钮弹出一个框,弹出的框可能是一段文件描述,也可能带有按钮操作 ...

  3. UIPresentationController - iOS自定义模态弹出框

    参考: https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/Definin ...

  4. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-4 模态弹出框--结构分析

    模态弹出框--结构分析 Bootstrap框架中的模态弹出框,分别运用了“modal”.“modal-dialog”和“modal-content”样式,而弹出窗真正的内容都放置在“modal-con ...

  5. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-3 模态弹出框

    模态弹出框(Modals) 这一小节我们先来讲解一个“模态弹出框”,插件的源文件:modal.js. 右侧代码编辑器(30行)就是单独引入 bootstrap 中发布出的“modal.js”文件. 样 ...

  6. 代码录播:jQueryMobile 实现一个简单的弹出框效果

    今天给大家带来的是 jQueryMobile 实现一个简单的弹出框效果,有兴趣的童鞋可以试试哦~ ^_^ 阅读原文:www.gbtags.com  

  7. bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form

    bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form

  8. html、css和js原生写一个模态弹出框,顺便解决父元素半透明子元素不透明效果

    模态框: html部分: <!-- 按钮 --> <button id="box" onclick="pop_box()">弹出框< ...

  9. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-1导入JavaScript插件

    导入JavaScript插件 Bootstrap除了包含丰富的Web组件之外,如前面介绍的下拉菜单.按钮组.导航.分页等.他还包括一些JavaScript的插件. Bootstrap的JavaScri ...

随机推荐

  1. SQL标量值函数:小写金额转大写

    我们日常开发业务系统中,作为统计报表中,特别是财务报表,显示中文金额经常遇到. 转换大小写的方法有很多,以下是从数据库函数方面解决这一问题. 效果如图: 调用:SELECT dbo.[Fn_Conve ...

  2. linux 的有用的网站

    从windows下移到linux下还有很长的路走阿,慢慢记录一些有用的网站吧 http://www.yolinux.com/ http://linux.die.net/

  3. 序列化 (C#)

    序列化是指将对象转换成字节流,从而存储对象或将对象传输到内存.数据库或文件的过程. 它的主要用途是保存对象的状态,以便能够在需要时重新创建对象. 反向过程称为"反序列化". 序列化 ...

  4. 使用配置类而不使用XML文件(代替bean.xml)对spring进行配置

    以下类是一个配置类,它的作用和bean.xml是一样的注解: @Configuration 作用: 用于指定当前类是一个spring配置类,当创建容器时会从该类上加载注解. 获取容器时需要使用Anno ...

  5. const define区别

    可以使用defined()----检测常量是否设置 [问]在php中定义常量时,const与define的区别? [答]使用const使得代码简单易读,const本身就是一个语言结构,而define是 ...

  6. java二分法查找实现代码

    package util; class BinarySearch { static int binarySearch(int[] array,int goal){//传入排好序的数组和目标数字 int ...

  7. 【转载】Hyperledger学习小结

    Hyperledger学习小结 自学Hyperledger Composer也有段时间了,是时候对所学的知识总结一下了.因为没有实际项目参与的话,差不多也就到此为止了.后续可能会去了解一下以太坊的技术 ...

  8. CTS/APIO后文化课游记

    根据ghj1222的尿性,干什么事都要写一个游记划水记啥的...然后就写嘛... 现在是5.30微机课,先开个坑,学校6.5放假,我将于6.5后开始更新本文 APIO回来后发生的事真的特别多...有的 ...

  9. JVM系列文章汇总

    JVM中运行时数据区中的堆.栈.方法区等区域的特性介绍 Java中class文件的组成结构 JVM的类加载生命周期介绍 Java堆.新生代老年代的特点.堆中的内存分配策略 JVM垃圾收集算法详解 JV ...

  10. C语言的头文件和宏定义详解

    原文链接:https://blog.csdn.net/abc_12366/article/details/79155540