這次帶給大家Vue實作PopupWindow元件使用步驟解析,Vue實作PopupWindow元件所使用的注意事項有哪些,下面就是實戰案例,一起來看一下。
這段時間一直在學習前端技術來完成自己的小專案。在js方面就使用了Vue框架。由於在專案裡想實現一個新建地址的PopupWindow效果,所以想到可以使用Vue的一些特性來實現。
使用到的Vue特性:元件(Component),props傳值,slot內容插入,transitions過渡動畫,x-templete模板。
直接上程式碼(完整程式碼可在連結中下載popupwindow):
html程式碼(無樣式):
e3af42622554aeed92ddd8262b7bc5c2 e388a4556c0f65e1904146cc1a846bee cd36aa8b22f666f4450411391120e8f6显示65281c5ac262bf6d81768915a4a77ac0 94b3e26ee717c64999d7867364b1b4a3 f7b78e6bbcbb11e2d4527fdc7db7c323 60554783aa2abf4f3b849a7b37c4b83c f140640d115cf0e0021e96ee8bc4d752 {{editTitle}} 94b3e26ee717c64999d7867364b1b4a3 f618256529daad59a61a381377af62b3 bb9345e55eb71822850ff156dfde57c8保存65281c5ac262bf6d81768915a4a77ac0 bb9345e55eb71822850ff156dfde57c8删除65281c5ac262bf6d81768915a4a77ac0 94b3e26ee717c64999d7867364b1b4a3 7b4cecaf82ef0b6672a89d3194cef4b5 94b3e26ee717c64999d7867364b1b4a3 bfa82c25df85a51d7e8b5dd1268a6ac4 bae5830ae524619b9a94fbf66d011e4f 6949a46a9a3f76c22b49640eaf357a01 e388a4556c0f65e1904146cc1a846bee a353f5e9cfd40556de4753bbf39843cd e388a4556c0f65e1904146cc1a846bee新建收货地址94b3e26ee717c64999d7867364b1b4a3 7971cf77a46923278913ee247bc958ee 94b3e26ee717c64999d7867364b1b4a3 e388a4556c0f65e1904146cc1a846bee e388a4556c0f65e1904146cc1a846bee收货人94b3e26ee717c64999d7867364b1b4a3 99e49d9bf4542b91ea6ba8d446bfd6ba 94b3e26ee717c64999d7867364b1b4a3 e388a4556c0f65e1904146cc1a846bee e388a4556c0f65e1904146cc1a846bee选择地区94b3e26ee717c64999d7867364b1b4a3 ff6d136ddc5fdfeffaf53ff6ee95f185 25edfb22a4f469ecb59f1190150159c6{{addressregion.province}}bed06894275b65c1ab86501b08a632eb 25edfb22a4f469ecb59f1190150159c6{{addressregion.city}}bed06894275b65c1ab86501b08a632eb 25edfb22a4f469ecb59f1190150159c6{{addressregion.region}}bed06894275b65c1ab86501b08a632eb 929d1f5ca49e04fdcb27f9465b944689 94b3e26ee717c64999d7867364b1b4a3 e388a4556c0f65e1904146cc1a846bee e388a4556c0f65e1904146cc1a846bee联系电话94b3e26ee717c64999d7867364b1b4a3 49b71cd208db6eea650e733ea1aa9404 94b3e26ee717c64999d7867364b1b4a3 e388a4556c0f65e1904146cc1a846bee e388a4556c0f65e1904146cc1a846bee详细地址94b3e26ee717c64999d7867364b1b4a3 b4659b3be8fe3eeb0dc06c56079c1620 94b3e26ee717c64999d7867364b1b4a3 e388a4556c0f65e1904146cc1a846bee e388a4556c0f65e1904146cc1a846bee邮政编码94b3e26ee717c64999d7867364b1b4a3 6edc5c742e0333399bfaaac3ef9c06d2 94b3e26ee717c64999d7867364b1b4a3 e388a4556c0f65e1904146cc1a846bee 4400c5c37b329c67fe0997f8625c5900 5dcca27b5f1e0fe5cd3faf8999c29349保存65281c5ac262bf6d81768915a4a77ac0 a718bbac80bb204c7eb6758a8221d7c4删除65281c5ac262bf6d81768915a4a77ac0 7971cf77a46923278913ee247bc958ee 94b3e26ee717c64999d7867364b1b4a3 94b3e26ee717c64999d7867364b1b4a3 6087faffb1c3f26530d25a6b190c2f81 2cacc6d41bbb37262a98f745aa00fbf0
js程式碼:
/* * 新建与编辑地址Vue组件popupwindow * */ var newAddressWindow = Vue.component("new-address-window",{ props: ['addressregion'], template: "#popup-window-address-new" }) /* * 地址popupwindow的Vue实例 * */ var chooseAddress = new Vue({ el: "#address-choose", data: { isShowEditWindow: true, isOneButton: false, editTitle: "新建收货地址", //填入初始地址信息,组件与改数据绑定 addressRegion: { } }, methods: { showOneBtnWindow: function(){ //显示新建收货地址对话框(有一个按钮) this.isShowEditWindow = true; this.isOneButton = false; this.editTitle = "新建收货地址"; }, removeEditWindow: function(){ //关闭新建与编辑地址选择对话框 this.isShowEditWindow = false; } } })
至此,一個popupwindow的元件就完成了。在實作一個Vue元件時,可以使用模板來實現元件,我在這裡採用了x-templete模板實作了元件,同時在元件通也可以使用vue的transition特性加入一些動畫效果。
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
以上是Vue實作PopupWindow元件使用步驟解析的詳細內容。更多資訊請關注PHP中文網其他相關文章!