使用vue實現點擊按鈕滑出面板的實現代碼,vue按鈕

來源:互聯網
上載者:User

使用vue實現點擊按鈕滑出面板的實現代碼,vue按鈕

在通訊的時候容易出錯,或者資訊根本傳不過來。那麼這裡就樣本一下,怎麼通過組件之間的通訊完成點擊事件。

index.vue檔案中:

<div>   <el-button type="primary" @click="onShow">點我</el-button></div>

傳遞中介

<addForm :show="formShow" @onHide="formShow = false"></addForm>

引入組件,即是要彈出的組件

import addForm from './docsForm'export default {components: {addForm},data() {return {show: false,formShow: false}},watch: { show: {      handler: function(newVal, oldVal) {        this.show = newVal      },      deep: true    }},methods: {onShow() {      this.formShow = true    }}}

該檔案裡面的方法就是這樣。

然後就是彈出組件docsForm.vue怎樣向上傳資料

<slidePanel :width="550" :show="show" title="添加知識" @changeShow="hide"><div class="docs-body"></div></slidePanel>export default {props: {show: false},methods: {hide() {      this.$emit('onHide')    },}

在組件slidePanel.vue中

<template>  <transition name="slide-panel-fade">    <div v-if="show" class="slide-panel" :style="{ width: width + 'px'}">      <div class="slide-panel-layout">        <div class="slide-panel-header">          <h3 class="slide-panel-header-title">{{title}}</h3>          <button class="slide-panel-header-close" @click="onShow"><i class="el-icon-close"></i></button>        </div>        <div class="slide-panel-body">          <slot></slot>        </div>      </div>    </div>  </transition></template><script>export default {  props: {    title: String,    show: Boolean,    width: {      type: Number,      default: 500    }  },  methods: {    onShow() {      this.$emit('changeShow', false)    }  },  watch: {    show: {      handler: function(newVal, oldVal) {        this.show = newVal      },      deep: true    }  },  mounted() {    document.body.appendChild(this.$el)  },  destroyed() {    this.$el.remove()  }}</script>

這樣就可以實現不同組件之間的冊拉彈出。

以上所述是小編給大家介紹的使用vue實現點擊按鈕滑出面板的實現代碼,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.