vue的通讯与传递props emit (简单的弹框组件)
props父把信息传递给子组件
1父组件
<template>
<div class="hello">
<div id="app-3" v-on:click="show">
点击显示隐藏
<p v-if="seen">现在可以看到我了</p>
</div>
<div class="app-4">
<ol>
<tab v-for="item in groceryList" v-bind:todo="item">
<!--:todo-->
</tab>
</ol>
</div>
<div class="app-5">
<p>{{message}}</p>
<input v-model="message">
<button v-on:click="reverse">逆转信息</button>
</div>
</div> </template> <script>
import Tab from '@/components/tab/tab'
export default {
name: 'hello',
components:{Tab},
data () {
return {
message:'Hello Vue!',
seen:true,
todos:[
{text:'学习javascript'},
{text:'学习Vue'}
],
groceryList: [
{ id: 0, text: '蔬菜' },
{ id: 1, text: '奶酪' },
{ id: 2, text: '随便其他什么人吃的东西' }
]
}
},
methods:{
show(){
this.seen=!this.seen;
},
reverse(){
this.message=this.message.split('').reverse().join('');
}
}
}
</script> <style scoped>
h1, h2 {
font-weight: normal;
} ul {
list-style-type: none;
padding: 0;
} li {
display: inline-block;
margin: 0 10px;
} a {
color: #42b983;
}
</style>
/****
******
*******
**********
*********/
子组件
<template>
<li>{{todo.id}}{{todo.text}}</li>
</template>
<script>
export default{
props:['todo'],/*通过这个把数据传过来*/
data(){
return{ }
},
methods:{ }
}
</script>
子组件传值给父元素
只展示重要代码
子组件
this.$emit('changeLocale',locale);
父组件
<v-header @changeLocale="paLocale"></v-header>
方法
paLocale(evtValue){
//evtValue表示子组件传递过来的locale值
},
简单的 弹窗组件编写
//父组件
<template>
<div class="parent">
<button @click="showModal">按钮</button>
<child v-if="showModel" header-title="温馨提示" @close="showModel = false" @closeModel="closeModel">
<div slot="body">
<p>你是傻逼吗?</p>
<p>你是!</p>
</div>
</child>
</div>
</template>
<script>
import child from '@/components/sub/child'
export default{
components:{child},
data(){
return{
showModel:false
}
},
methods:{
showModal(){
this.showModel=true
},
closeModel(){
this.showModel=false
}
}
}
</script>
<style> </style>
//子组件
<template>
<transition name="model">
<div class="model" >
<div class="model-mask" @click="close"></div>
<div class="modal-wrapper">
<div class="modal-header">
<slot name="header">
{{headerTitle}}
</slot>
</div> <div class="modal-body">
<slot name="body">
default body
</slot>
</div> <div class="modal-footer">
<slot name="footer"> <button class="modal-default-button" @click="close">
OK
</button>
</slot>
</div>
</div>
</div>
</transition>
</template>
<script>
export default{
props:['headerTitle'],
methods:{
close(){
this.$emit('closeModel');
}
}
}
</script>
<style scoped>
.model{
position: fixed;
z-index: 96;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.model-mask{
position: fixed;
z-index: 97;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
transition: opacity .3s ease;
}
.modal-wrapper{
position: relative;
width:80%;
height: auto;
margin: 0 auto;
margin-top: 100px;
padding: 20px 30px;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
transition: all .3s ease;
z-index:98;
}
.model-enter-active, .model-leave-active{
transition: opacity .5s;
opacity:1;
}
.model-enter, .model-leave-to {
opacity: 0
}
</style>

vue的通讯与传递props emit (简单的弹框组件)的更多相关文章
- vue移动端弹框组件,vue-layer-mobile
最近做一个移动端项目,弹框写的比较麻烦,查找资料,找到了这个组件,但是说明文档比较少,自己研究了下,把我碰到的错,和详细用法分享给大家!有疑问可以打开组件看一看,这个组件是仿layer-mobile的 ...
- vue移动端弹框组件
最近做一个移动端项目,弹框写的比较麻烦,查找资料,找到了这个组件,但是说明文档比较少,自己研究了下,把我碰到的错,和详细用法分享给大家!有疑问可以打开组件看一看,这个组件是仿layer-mobile的 ...
- vue封装一个弹框组件
这是一个提示框和对话框,例: 这是一个组件 eject.vue <template> <div class='kz-cont' v-show='showstate'> &l ...
- Vue.js学习(八)—— 树形结构下拉框组件vue-treeselect
vue-treeselect是一个多选组件,具有对Vue.js的嵌套选项支持. 具有嵌套选项支持的单个和多个选择 模糊匹配 异步搜索 延迟加载(仅在需要时加载深层选项的数据) 键盘支持(使用Arrow ...
- 移动端(H5)弹框组件--简单--实用--不依赖jQuery
俗话说的好,框架是服务与大家的,包含的功能比较多,代码多.在现在追求速度的年代.应该根据自己的需求去封装自己所需要的组件. 下边就给大家介绍一下自己封装的一个小弹框组件,不依赖与jQuery,代码少, ...
- vue+elementui 新增和编辑如何实现共用一个弹框
//html代码: //按钮 <el-button type="primary" size="medium" @click="addEquipm ...
- 【jQuery学习】写一个简单的弹框页面,火狐浏览器有弹框,但IE8没有弹框的原因?
我也是刚学习jQuery,就从官网上下载了jQuery的包,版本是3.2.1 代码 如下: <!DOCTYPE html> <html> <head> <me ...
- Vue简单基础 + 实例 及 组件通信
vue的双向绑定原理:Object.defineProperty() vue实现数据双向绑定主要是:采用数据劫持结合发布者-订阅者模式的方式,通过 Object.defineProperty() 来劫 ...
- 基于Vue.js PC桌面端弹出框组件|vue自定义弹层组件|vue模态框
vue.js构建的轻量级PC网页端交互式弹层组件VLayer. 前段时间有分享过一个vue移动端弹窗组件,今天给大家分享一个最近开发的vue pc端弹出层组件. VLayer 一款集Alert.Dia ...
随机推荐
- TFS登录时保存了用户密码,如何用其他账户登录
来源:http://blog.csdn.net/littlegreenfrog/article/details/5254633 使用TFS2008过程中,常常由于已经保存用户名和密码,却没有重新登 ...
- 吴裕雄 python神经网络 水果图片识别(5)
#-*- coding:utf-8 -*-### required libaraiedimport osimport matplotlib.image as imgimport matplotlib. ...
- tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT')
tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') tf.pad 是扩展的意思,其中[0, 0], [1, 0] 分别代表的是[上, ...
- SPSS-判别分析
判别分析 判别分析是一种有效的对个案进行分类分析的方法.和聚类分析不同的是,判别分析时组别的特征已知. 定义:判别分析先根据已知类别的事物的性质,利用某种技术建立函数式,然后对未知类别的新事物进 行判 ...
- DM 9000网卡驱动移植
1. 由于内核已经带有DM9000 网卡的驱动,所以主要移植工作是在板文件中添加 platform_device 结构,并加入 ok6410_devices[] __initdata 数组. 代码如下 ...
- Python+Appium自动化环境搭建
appium工作原理 appium 在android端工作流 client端也就是我们 test script是我们的webdriver测试脚本. 中间是起的Appium的服务,Appium在服务端起 ...
- eclipse egit(版本回退)
在公司一年多了,用到的项目都是用svn代码托管,没有git 的用武之地,趁国庆假期稍微自学了一下,然后人比较懒,不愿用原生敲命令行的形式,就在eclipse上学学怎么用git,话说回来用了svn再来学 ...
- propTypes
[propTypes] React.PropTypes is deprecated as of React v15.5. Please use the prop-types library inste ...
- python文件操作之二进制
列表项 三元运算符号: a=3 b=7 val=a if a>b else val=b print(val) 文件处理 首先给你一个文件,或者自己建立一个文件,那如何查看文件的内容呢? 1.安装 ...
- 早上STO单紧急寻源处理
truncate table SAP_SO_STO1_STO2; truncate table SAP_STO1_STO2; INSERT INTO STG.SAP_SO_STO1_STO2(VBEL ...