Vue項(xiàng)目結(jié)合Vue-layer實(shí)現(xiàn)彈框式編輯功能(實(shí)例代碼)
1. 實(shí)現(xiàn)效果

2.實(shí)現(xiàn)原理
在父組件中點(diǎn)擊編輯按鈕,將當(dāng)前點(diǎn)擊對象的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>賬號</label>
<input type="text" required placeholder="賬號" 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="超級管理員" >超級管理員</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:{
//用來顯示對應(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í)砑訉?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)文章
vue點(diǎn)擊按鈕動(dòng)態(tài)創(chuàng)建與刪除組件功能
這篇文章主要介紹了vue點(diǎn)擊按鈕動(dòng)態(tài)創(chuàng)建與刪除組件功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
vue-element-admin中node-sass換成dart-sass,安裝依賴報(bào)code?128多種問題的解決
這篇文章主要介紹了vue-element-admin中node-sass換成dart-sass,安裝依賴報(bào)code?128多種問題的解決方法,本文給大家分享問題原因分析及解決方法,需要的朋友可以參考下2023-02-02
vue項(xiàng)目怎樣用nginx反向代理WebSocket請求地址
這篇文章主要介紹了vue項(xiàng)目怎樣用nginx反向代理WebSocket請求地址問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09
Vue3中引入SCSS和LESS依賴的基本步驟和注意事項(xiàng)
我們項(xiàng)目開發(fā)中經(jīng)常遇到樣式里面會使用less和scss寫法, less,scss和stylus都是css的預(yù)處理器,這篇文章主要給大家介紹了關(guān)于Vue3中引入SCSS和LESS依賴的基本步驟和注意事項(xiàng),需要的朋友可以參考下2024-05-05
在?Vite項(xiàng)目中使用插件?@rollup/plugin-inject?注入全局?jQuery的過程詳解
在一次項(xiàng)目腳手架升級的過程中,將之前基于?webpack?搭建的項(xiàng)目移植到?Vite?構(gòu)建,這篇文章主要介紹了在?Vite項(xiàng)目中,使用插件?@rollup/plugin-inject?注入全局?jQuery,需要的朋友可以參考下2022-12-12
webpack安裝配置與常見使用過程詳解(結(jié)合vue)
這篇文章主要介紹了webpack安裝配置與常見使用過程,主要結(jié)合vue實(shí)現(xiàn),通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06

