Vue項(xiàng)目結(jié)合Vue-layer實(shí)現(xiàn)彈框式編輯功能(實(shí)例代碼)
1. 實(shí)現(xiàn)效果
2.實(shí)現(xiàn)原理
在父組件中點(diǎn)擊編輯按鈕,將當(dāng)前點(diǎn)擊對(duì)象的id傳給子組件,子組件根據(jù)id修改相應(yīng)的內(nèi)容
父組件中代碼:
//放置編輯按鈕的位置 <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" v-on:click="edit(manage.id)"><i class="layui-icon"></i>編輯</button> // 在methods中設(shè)計(jì)edit()方法 //需要先引入編輯組件 import EditManage from './EditManage' edit(id){ this.$layer.iframe({ type:2, title:"編輯", area:['600px','450px'], shade:true, offset:'auto', content:{ content:EditManage,//傳遞的編輯組件主線 parent:this, data:{ info:{id:id}// 傳遞的要編輯內(nèi)容的id值 } } }) },
子組件EditManage代碼
<template> <div class="editmanage container"> <form class="form" v-on:submit="editManage"> <div class="form-group"> <label>賬號(hào)</label> <input type="text" required placeholder="賬號(hào)" autocomplete="off" class="form-control" v-model="manage.account"> </div> <div class="form-group"> <label>用戶名</label> <input type="text" required placeholder="用戶名" autocomplete="off" class="form-control" v-model="manage.username"> </div> <div class="form-group"> <label >密碼</label> <input type="password" required placeholder="密碼" autocomplete="off" class="form-control" v-model="manage.password"> </div> <div class="form-group"> <label >權(quán)限</label> <select name="authority" class="form-control" v-model="manage.authority"> <option value="超級(jí)管理員" >超級(jí)管理員</option> <option value="普通管理員" >普通管理員</option> </select> </div> <button type="submit" class="btn btn-info">立即提交</button> </form> </div> </template> <script> export default { name: 'addmanage', data () { return { manage:{}, form:{} } }, props:{ //接收父組件傳來的id值 info:{ type:Object, default:()=>{ return {} } }, layerid:{ type:String, default:"" }, lydata:{ type:Object, default:()=>{ return {} } } }, methods:{ //用來顯示對(duì)應(yīng)id的編輯內(nèi)容,在created中調(diào)用 fetchManage(id){ this.$http.get('http://localhost:3000/manage/'+id) .then(function (response) { this.manage=response.body; }) }, editManage(e){ if(!this.manage.account||!this.manage.username||!this.manage.password||!this.manage.authority){ this.$layer.msg("請?zhí)砑訉?duì)應(yīng)信息!") }else{ let updateManage={ account:this.manage.account, username:this.manage.username, password:this.manage.password, authority:this.manage.authority }; this.$http.put("http://localhost:3000/manage/"+this.info.id,updateManage) .then(function (response) { //關(guān)閉父組件中的編輯彈框 this.$layer.close(this.layerid); //彈出提示信息,默認(rèn)時(shí)間為3秒 this.$layer.msg("修改管理員信息成功!"); }); e.preventDefault() } e.preventDefault() } }, created(){ // this.info.id父組件傳給子組件的id值 this.fetchManage(this.info.id); } } </script> <style scoped> .editmanage{ margin:8px 20px 20px 20px; } </style>
到此這篇關(guān)于Vue項(xiàng)目結(jié)合Vue-layer實(shí)現(xiàn)彈框式編輯功能(實(shí)例代碼)的文章就介紹到這了,更多相關(guān)Vue彈框式編輯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 解決vue多層彈框時(shí)存在遮擋問題
- vue+elementui 實(shí)現(xiàn)新增和修改共用一個(gè)彈框的完整代碼
- vue自定義彈框效果(確認(rèn)框、提示框)
- vue實(shí)現(xiàn)可拖拽的dialog彈框
- 解決echarts vue數(shù)據(jù)更新,視圖不更新問題(echarts嵌在vue彈框中)
- vue+elementui實(shí)現(xiàn)點(diǎn)擊table中的單元格觸發(fā)事件--彈框
- Vue自定義render統(tǒng)一項(xiàng)目組彈框功能
- vue項(xiàng)目中使用vue-layer彈框插件的方法
- Vue自定義詢問彈框和輸入彈框的示例代碼
相關(guān)文章
關(guān)于vue 結(jié)合原生js 解決echarts resize問題
這篇文章主要介紹了關(guān)于vue 結(jié)合原生js 解決echarts resize問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07詳解VUE 定義全局變量的幾種實(shí)現(xiàn)方式
本篇文章主要介紹了VUE 全局變量的幾種實(shí)現(xiàn)方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06vue動(dòng)態(tài)設(shè)置頁面title的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于vue動(dòng)態(tài)設(shè)置頁面title的相關(guān)資料,文中通過實(shí)例代碼結(jié)束的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08vue+el-table點(diǎn)擊表頭實(shí)現(xiàn)改變其當(dāng)前樣式
這篇文章主要介紹了vue+el-table點(diǎn)擊表頭實(shí)現(xiàn)改變其當(dāng)前樣式問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08