美文网首页
vue子组件向父组件传值和实现'抽屉'弹出

vue子组件向父组件传值和实现'抽屉'弹出

作者: 正版Figo | 来源:发表于2018-11-21 19:20 被阅读0次

子组件


<style>

</style>

<template>
    <div>
        <transition name="slide-fade">
            <div class="side-content">
                <div class="close" @click="close">取消</div>
                <slot name="main"></slot>
            </div>
        </transition>
    </div>
</template>
<script>
export default {
  data() {
    return {
      todos: false,
    };
  },
  created() {
    
  },
  mounted() {
      
    },
  methods: {
    close() {
        this.$emit('childEvent',this.todos);
    }
  }
};
</script>

父组件


<template>
    <div>
        <el-button @click="open">打开</el-button>
        <transition name="popup">
          <Demo @childEvent="parentMethod" v-show="side" class="pop-up" @touchmove.stop.prevent>
            <template slot="main">
                <h1>页面标题</h1>
                <p>A paragraph for the main content.</p>
                <p>And another one.</p>
                <input type="text">
              </template>
          </Demo>
        </transition>
    </div>
</template>
<style>
/* /抽屉 */
.pop-up{
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  opacity: 1;
  z-index: 502;
  background: rgba(0, 0, 0, 0.5);
}
.popup-enter-to,
.popup-leave-to {
  transition: transform 0.3s;
  transform: translate(0px, 0px);
}

.popup-enter,
.popup-leave-to {
  opacity: 0;
  -webkit-transform: translate(0px, 100%);
  transform: translate(0px, 100%);
  -webkit-transition: opacity 0.3s ease-in-out 0.3s,
    -webkit-transform 0.3s ease-in-out;
  transition: opacity 0.3s ease-in-out 0.3s, transform 0.3s ease-in-out;
}

/* end */
.side-content {
  z-index: 503;
  position: fixed;
  background: #ffffff;
  top: 200px;
  left: 10px;
  bottom: 100px;
  right: 10px;
  -webkit-overflow-scrolling: touch;
}

.close {
  padding: 17px;
  text-align: left;
  color: rgba(0, 122, 255, 1);
}
</style>

<script>
import API from "@/js/API.js";
import Demo from "./Demo";

export default {
  data() {
    return {
      side: false, //抽屉
    };
  },
  components: {
    Demo
  },
  created() {},
  methods: {
    parentMethod(data) {
      this.side = false;
      console.log(data);
      
    },
    open() {
      this.side = true;
    }
  }
};
</script>

相关文章

  • Vue - 传值

    Vue 传值有两种:1)父组件向子组件传值(属性传值,Prop传值)2)子组件向父组件传值 一、父组件向子组件传值...

  • 2019-03-13

    vue父子组件传值,(父组件向子组件传值用prop ,子组件向父组件传值:子组件调用父组件方法值以参数的方式传递)...

  • 2019-03-13

    vue父子组件传值,(父组件向子组件传值用prop ,子组件向父组件传值:子组件调用父组件方法值以参数的方式传递)...

  • vue2.0的三种常用传值方式,并且如何实现?

    vue2.0 组件传值方式有三种:父组件向子组件传值,子组件向父组件传值,非父子组件传值 : 父传子: 首先现在父...

  • 04vue2.0-Vue组件化-组件间的数据传递

    Vue组件之间传值 父组件向子组件传值 1.父组件向子组件传值 父组件发送的形式是以属性的形式绑定值到子组件身上。...

  • Vue组件传值

    vue组件传值 一、父组件向子组件传值方式: 1. 子组件中定义props,父组件向子组件props进行传值。 2...

  • 前端-vue框架学习笔记(二)-传值

    环境:vue-cli+webstorm 目录 1. 父组件向子组件传值 2. 子组件向父组件传值 3. 父组件向子...

  • vue中父子组件传值

    vue中父子组件传值是经常使用的场景 父组件向子组件中传值 父组件 子组件 父组件向子组件中传值分三步1、在父组件...

  • vue父子组件的双向绑定

    父组件可以向子组件传值,修改。同时,子组件也可以向父组件传值和修改 父组件的分析:父组件使用v-model实现双向...

  • ReactNative组件间的通信

    父组件向子组件通信 父组件向子组件传值 父组件向子组件传递方法 子组件向父组件通信 子组件向父组件传值 子组件向父...

网友评论

      本文标题:vue子组件向父组件传值和实现'抽屉'弹出

      本文链接:https://www.haomeiwen.com/subject/tkqhqqtx.html