使用vue實(shí)現(xiàn)點(diǎn)擊按鈕滑出面板的實(shí)現(xiàn)代碼
在通信的時(shí)候容易出錯(cuò),或者信息根本傳不過(guò)來(lái)。那么這里就示例一下,怎么通過(guò)組件之間的通信完成點(diǎn)擊事件。
index.vue文件中:
<div> <el-button type="primary" @click="onShow">點(diǎn)我</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怎樣向上傳數(shù)據(jù)
<slidePanel :width="550" :show="show" title="添加知識(shí)" @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>
這樣就可以實(shí)現(xiàn)不同組件之間的冊(cè)拉彈出。
以上所述是小編給大家介紹的使用vue實(shí)現(xiàn)點(diǎn)擊按鈕滑出面板的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- vue實(shí)現(xiàn)點(diǎn)擊按鈕下載文件功能
- vue.js 實(shí)現(xiàn)點(diǎn)擊按鈕動(dòng)態(tài)添加li的方法
- vue 點(diǎn)擊按鈕增加一行的方法
- Vue.js點(diǎn)擊切換按鈕改變內(nèi)容的實(shí)例講解
- 解決vue 按鈕多次點(diǎn)擊重復(fù)提交數(shù)據(jù)問(wèn)題
- vue組件中點(diǎn)擊按鈕后修改輸入框的狀態(tài)實(shí)例代碼
- 基于vue實(shí)現(xiàn)滾動(dòng)條滾動(dòng)到指定位置對(duì)應(yīng)位置數(shù)字進(jìn)行tween特效
- vue elementUI table表格數(shù)據(jù) 滾動(dòng)懶加載的實(shí)現(xiàn)方法
- vue中實(shí)現(xiàn)點(diǎn)擊按鈕滾動(dòng)到頁(yè)面對(duì)應(yīng)位置的方法(使用c3平滑屬性實(shí)現(xiàn))
相關(guān)文章
vue3?+?Ant?Design?實(shí)現(xiàn)雙表頭表格的效果(橫向表頭+縱向表頭)
這篇文章主要介紹了vue3?+?Ant?Design?實(shí)現(xiàn)雙表頭表格(橫向表頭+縱向表頭),需要的朋友可以參考下2023-12-12element-ui 中使用upload多文件上傳只請(qǐng)求一次接口
這篇文章主要介紹了element-ui 中使用upload多文件上傳只請(qǐng)求一次接口,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07vue項(xiàng)目拍照或上傳圖片并實(shí)現(xiàn)轉(zhuǎn)化為base64格式
這篇文章主要介紹了vue項(xiàng)目拍照或上傳圖片并實(shí)現(xiàn)轉(zhuǎn)化為base64格式方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11vue實(shí)現(xiàn)簡(jiǎn)單的分頁(yè)功能
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)簡(jiǎn)單的分頁(yè)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03用vue的雙向綁定簡(jiǎn)單實(shí)現(xiàn)一個(gè)todo-list的示例代碼
本篇文章主要介紹了用vue的雙向綁定簡(jiǎn)單實(shí)現(xiàn)一個(gè)todo的示例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08vue項(xiàng)目中l(wèi)ess的一些使用小技巧
前段時(shí)間一直在學(xué)習(xí)vue,開始記錄一下遇到的問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目中l(wèi)ess的一些使用小技巧,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-09-09