vue彈窗父子組件調(diào)用問題示例詳解
一、vue彈窗 父子組件 emit 傳圖片
1、:modal-append-to-body="false"為了解決element ui中引入dialog窗口組件后遮罩層會擋住dialog窗口的用處,默認(rèn)為true,改為false即可解決。
2、此彈窗主要為了解決收到下位機(jī)急停信號后,上位機(jī)前臺顯示彈窗的重復(fù)性。
//此為子組件(customComponents.vue)
<div>
<el-dialog
:visible.sync="dialogVisible"
width="25%"
:modal-append-to-body="false">
<div slot="title" class="dialog-header-title">
<img :src="url" >
<span> 提示</span>
</div>
<span>{{this.message}}</span>
<span slot="footer" class="dialog-footer">
<el-button
type="primary"
size="small"
@click="dialogVisible = false" >確 定 </el-button>
</span>
</el-dialog>
</div>
<script>
export default {
props: {
url: String,//String為定義參數(shù)類型,例如圖片地址就是String類型的
message: String,//String為定義參數(shù)類型
},
data() {
return {
dialogVisible: true,
};
},
}
</script>//此為父組件(treatmentInterface.vue)
<customComponents
v-if="empStopStatus== 0"
:url="iconDanger"
:message='messageDanger' ></customComponents>
<div v-else></div>
<script>
//引入局部組件(子組件)
import customComponents from "../customComponents/customComponents"
export default {
name: " ",
components: {customComponents},
data() {
return {
iconDanger: require('../../assets/icons/customComponents/danger.png'),
messageDanger: "急停按鈕被按下!請先檢查設(shè)備...",
};
},
}
</script>二、vue父組件調(diào)用子組件里的不同方法
1、vue的動態(tài)方法綁定
主要看:
①:<el-button>標(biāo)簽里的@click
②:methods里面的buttonClick(methodName)
//此為子組件(customComponents.vue)
<div>
<el-dialog
:visible.sync="dialogVisible"
width="25%"
:modal-append-to-body="false">
<div slot="title" class="dialog-header-title">
<img :src="url" >
<span> 提示</span>
</div>
<span>{{this.message}}</span>
<span slot="footer" class="dialog-footer">
<el-button
type="primary"
size="small"
@click="buttonClick(methodsName)">確 定</el-button>
</span>
</el-dialog>
</div>
<script>
export default {
props: {
url: String,//String為定義參數(shù)類型,例如圖片地址就是String類型的
message: String,//String為定義參數(shù)類型
},
data() {
return {
dialogVisible: true,
};
},
methods:{
buttonClick(methodName) {
this[methodName]()
},
treatFinished() {
console.log("執(zhí)行了..........")
},
emergencyStop() {
this.dialogVisible = false
}
},
}
</script>至此,已完成子組件里不同方法的綁定,下一步就要在父組件里調(diào)用上方子組件里的方法了。
2、父組件調(diào)用子組件方法
//此為父組件(treatmentInterface.vue)
<!-- 治療完成彈窗 -->
<customComponents
v-if="treatStatus== 1"
:url="iconDone"
:message='messageFinished'
:methodsName='treatFinished'></customComponents>
<div v-else></div>
<!-- 急停被按下彈窗 -->
<customComponents
v-if="empStopStatus== 0"
:url="iconDanger"
:message='messageDanger'
:methodsName='emergencyStop'></customComponents>
<div v-else></div>
<script>
//引入局部組件(子組件)
import customComponents from "../customComponents/customComponents"
export default {
components: {customComponents},
data() {
return {
iconDanger: require('../../assets/icons/customComponents/danger.png'),
messageDanger: "急停按鈕被按下!請先檢查設(shè)備...",
treatFinished: 'treatFinished',
emergencyStop: 'emergencyStop',
};
},
}
</script>到此這篇關(guān)于vue彈窗父子組件調(diào)用的文章就介紹到這了,更多相關(guān)vue父子組件調(diào)用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue第三方庫中存在擴(kuò)展運(yùn)算符報錯問題的解決方案
這篇文章主要介紹了vue第三方庫中存在擴(kuò)展運(yùn)算符報錯問題,本文給大家分享解決方案,通過結(jié)合實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07
VUE v-model表單數(shù)據(jù)雙向綁定完整示例
這篇文章主要介紹了VUE v-model表單數(shù)據(jù)雙向綁定,結(jié)合完整實例形式分析了vue.js實現(xiàn)表單數(shù)據(jù)雙向綁定相關(guān)操作技巧,需要的朋友可以參考下2019-01-01
解決el-tree節(jié)點(diǎn)過濾不顯示下級的問題
這篇文章主要介紹了解決el-tree節(jié)點(diǎn)過濾不顯示下級的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04
vue使用vue-video-player無法播放本地視頻的問題及解決
這篇文章主要介紹了vue使用vue-video-player無法播放本地視頻的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
Vue+tracking.js 實現(xiàn)前端人臉檢測功能
這篇文章主要介紹了Vue+tracking.js 實現(xiàn)前端人臉檢測功能,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
Vue在頁面數(shù)據(jù)渲染完成之后的調(diào)用方法
今天小編就為大家分享一篇Vue在頁面數(shù)據(jù)渲染完成之后的調(diào)用方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
vue-cli3 項目從搭建優(yōu)化到docker部署的方法
這篇文章主要介紹了vue-cli3 項目從搭建優(yōu)化到docker部署的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01

