vue實(shí)現(xiàn)模態(tài)框的通用寫法推薦
在看了element組件的源碼后發(fā)現(xiàn),所有模態(tài)框其實(shí)實(shí)現(xiàn)方法都差不多,主要用到了vue在組件化上的雙向綁定。代碼:
<!--查看槽點(diǎn)對話框--> <template lang="html"> <transition name="el-fade-in-linear"> <div draggable="true" @drag="mouseDrag" @dragend="mouseDragend" :style="dialogStyle" class="g-dialog-wrapper" v-show="myVisible"> <div class="g-dialog-header"> <div class="left"> 模態(tài)框 </div> <div class="right"> <i class="g-times-icon fa fa-times" @click="myVisible=false" aria-hidden="true"></i> </div> </div> <div class="g-dialog-container"> </div> </div> </transition> </template> <script> export default { props: { visible: Boolean }, created() { }, data() { return { myVisible: this.visible, }, computed: {}, methods: { }, components: {}, watch: { myVisible: function (val) { this.$emit('update:visible', val) }, visible: function (val) { this.myVisible = val } } } </script> <style lang="css" scoped> </style>
上面代碼主要的部分是watch里面的代碼,實(shí)現(xiàn)監(jiān)聽數(shù)據(jù)變化,及時(shí)更新。所以在使用的時(shí)候就很方便了,在component注冊組件之后:
<g-key-dialog :visible.sync="keyDialogVisible"></g-key-dialog>
注:這里必須使用sync,要不是無法雙向綁定的
以上這篇vue實(shí)現(xiàn)模態(tài)框的通用寫法推薦就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Vue.js彈出模態(tài)框組件開發(fā)的示例代碼
- vue+element 模態(tài)框表格形式的可編輯表單實(shí)現(xiàn)
- 利用vue實(shí)現(xiàn)模態(tài)框組件
- vue+element模態(tài)框中新增模態(tài)框和刪除功能
- vue.extend實(shí)現(xiàn)alert模態(tài)框彈窗組件
- 詳解如何用VUE寫一個(gè)多用模態(tài)框組件模版
- vue移動(dòng)端模態(tài)框(可傳參)的實(shí)現(xiàn)
- 詳解vue父子組件關(guān)于模態(tài)框狀態(tài)的綁定方案
- Vue.extend 登錄注冊模態(tài)框的實(shí)現(xiàn)
- Vue?dialog模態(tài)框的封裝方法
相關(guān)文章
關(guān)于vue.js v-bind 的一些理解和思考
本篇文章主要介紹了關(guān)于vue.js v-bind 的一些理解和思考,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06vue使用動(dòng)畫實(shí)現(xiàn)滾動(dòng)表格效果
這篇文章主要為大家詳細(xì)介紹了vue使用動(dòng)畫實(shí)現(xiàn)滾動(dòng)表格效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04Vue3 + TypeScript 開發(fā)總結(jié)
本文直接上 Vue3 + TypeScript + Element Plus 開發(fā)的內(nèi)容,感興趣的話一起來看看吧2021-08-08axios中post請求json和application/x-www-form-urlencoded詳解
Axios是專注于網(wǎng)絡(luò)數(shù)據(jù)請求的庫,相比于原生的XMLHttpRequest對象,axios簡單易用,下面這篇文章主要給大家介紹了關(guān)于axios中post請求json和application/x-www-form-urlencoded的相關(guān)資料,需要的朋友可以參考下2022-10-10