运用的知识点包括:

路由的配置

插槽

vue的过渡动画

路由重定向

router/index.js里面配置路由

import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/home'
import About from '@/components/about' Vue.use(Router) export default new Router({
mode:'history',
routes: [
{
path: '/home',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: About
},
{ path: '/', redirect:'/home' } ]
})

app.vue

<template>
<div id="app">
<router-link :to="{path:'/home'}">home</router-link>
<router-link :to="{path:'/about'}">about</router-link>
<router-view/>
</div>
</template> <script>
export default {
name: 'App'
}
</script> <style>
#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;
}
</style>

home.vue

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

about.vue

<template>
<div class="about">
<p>{{aboutmsg}}</p>
<button @click="openHomeModal()">打开about里面的modal</button>
<transition name="slide-fade">
<v-modal v-show="modalStatus" :title="title" :content="content"> <slot>
     <button v-for="item in btnType" :class="item.class" @click="modalStatus=false">
      {{item.vlaue}}
      </button>
      </slot>
</v-modal>
</transition>
</div>
</template>
<script>
import Modal from "@/components/modal.vue";
export default {
data() {
return {
modalStatus: false,
aboutmsg: "我是关于页面",
title: "我是关于页面的title",
content: "我是关于页面的内容",
    btnType:["value":"确定","class":"default"]
};
},
methods: {
openHomeModal() {
this.modalStatus = true;
}
},
components: {
"v-modal": Modal
}
};
</script>
<style lang="scss"> /* 可以设置不同的进入和离开动画 */
/* 设置持续时间和动画函数 */
.slide-fade-enter-active {
transition: all .3s ease;
}
.slide-fade-leave-active {
transition: all .2s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active for below version 2.1.8 */ {
transform: translateY(-10px); //从上面下移,逐渐出现
opacity: 0;
}
</style>

modal.vue

<template>
<div class="modal">
<div class="header">{{title}}</div>
<div class="content">{{content}}</div>
<div class="footer">
<slot></slot>
</div>
</div>
</template>
<script>
export default{
data(){
return {}
},
props:['title','content'], }
</script>
<style lang="scss">
.modal {
width:500px;
height:400px;
position: absolute;
top:50%;
left:50%;
margin-toP:-250px;
margin-left:-200px;
border:1px solid #666;
.header {
height:60px;
line-height:60px;
text-align: center;
background:#666;
border-bottom: 1px solid #000;
box-sizing: border-box;
}
.content {
background:orange;
height:290px; }
.footer {
height:50px;
line-height: 50px;
button {
vertical-align: middle;
display: inline-block;
width:80px;
height:40px;
line-height: 40px;
color:#fff;
&.danger{
background:red; }
&.default{
background:#ddd;
} } }
}
</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. Unity实现支持泛型的事件管理以减少使用object作为参数带来的频繁装拆箱

    如果不用C#自身的event关键字而是要自己实现一个可统一管理游戏中各种消息事件通知管理的系统模块EventManger时,通常都是把事件delegate的参数定义为object类型以适应所有的数据类 ...

  2. p2921 Trick or Treat on the Farm

    传送门 题目 每年万圣节,威斯康星的奶牛们都要打扮一番,出门在农场的N个牛棚里转 悠,来采集糖果.她们每走到一个未曾经过的牛棚,就会采集这个棚里的1颗糖果.农场不大,所以约翰要想尽法子让奶牛们得到快乐 ...

  3. 【Redis】Redis事务详解,Redis事务支持回滚(不支持悲观锁)

    1.redis事物参考:https://baijiahao.baidu.com/s?id=1613631210471699441&wfr=spider&for=pc (php操作red ...

  4. linux下sed批量替换文件内容

    在linux超级终端下编辑文档是件比较麻烦的事情,下面简单介绍一下如何在linux下批量替换文件内容 linuxsed 批量替换多个文件中的字符串 格式: sed -i "s/查找字段/替换 ...

  5. MySQL 文件导入出错

    ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec ...

  6. js常用util

    /** 日期格式化 */Date.prototype.Format = function(format) { var o = {  "M+" : this.getMonth() + ...

  7. C# 将数组转换为以逗号分隔的字符串

    例子: string[] array = { "A", "B", "C", "D" }; string str = st ...

  8. 22. Generate Parentheses (recursion algorithm)

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  9. Spark Streaming 的容错

    Spark Streaming 为了实现容错特性,接收到的数据需要在集群的多个Worker 节点上的 executors 之间保存副本(默认2份).当故障发生时,有两种数据需要恢复: 1. 已接收并且 ...

  10. Ruby中如何识别13位的时间戳

    由于13位的时间戳在Ruby中是比较另类的,以为Ruby中默认的时间戳都是10位的.而Time和Date是Ruby中常用的处理时间的模块. 由于最初遇到问题的时候网上搜了好久都没找到合适的,因此就自己 ...