vue彈窗組件使用方法
本文實(shí)例為大家分享了vue彈窗組件的具體代碼,供大家參考,具體內(nèi)容如下
彈窗是一個(gè)項(xiàng)目必備的復(fù)用利器,所以封裝起來,保證項(xiàng)目ui一致,是很有必要的。學(xué)了一段時(shí)間vue,想想還是用vue寫一下吧。用的很小白,但是會(huì)寫出來了,說明我也有進(jìn)步一丟丟了。繼續(xù)加油….
代碼貼圖如下,樣式比較丑,不要介意…
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ys-vue-modal-component</title>
<style>
p,h4{
margin:0;
}
.modal{
width: 480px;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, .3);
border-radius: 6px;
box-shadow: 0 4px 12px rgba(0, 0, 0, .5);
margin: 50px;
}
.modal-header {
color: #fff;
background: cadetblue;
border-radius: 6px 6px 0 0;
padding: 15px;
border-bottom: 1px solid #5e9fa1;
}
.modal-content div {
padding: 15px 10px;
}
.modal-footer {
padding: 15px;
text-align: right;
border-top: 1px solid #e5e5e5;
}
.btn {
border: 1px solid #d1d1d1;
border-radius: 3px;
background-color: #f7f7f7;
background: -webkit-gradient(linear, 0 0, 0 100%, from(#f7f7f7),
to(#f2f2f2));
background: -moz-gradient(linear, 0 0, 0 100%, from(#f7f7f7),
to(#f2f2f2));
background: -o-gradient(linear, 0 0, 0 100%, from(#f7f7f7), to(#f2f2f2));
background: -ms-gradient(linear, 0 0, 0 100%, from(#f7f7f7), to(#f2f2f2));
height: 28px;
padding: 0 20px;
cursor: pointer;
line-height: 28px;
display: inline-block;
color: #666666;
margin-right: 5px;
outline: none;
}
.blue {
border: 1px solid #5e9fa1;
background-color: #5e9fa1;
background: -webkit-gradient(linear, 0 0, 0 100%, from(#74c4c6),
to(#5e9fa1));
background: -moz-gradient(linear, 0 0, 0 100%, from(#74c4c6),
to(#5e9fa1));
background: -o-gradient(linear, 0 0, 0 100%, from(#74c4c6), to(#5e9fa1));
background: -ms-gradient(linear, 0 0, 0 100%, from(#74c4c6), to(#5e9fa1));
color: #FFFFFF;
}
</style>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<input type="button" class="btn blue" value="點(diǎn)擊我,呼喚彈窗,再來一遍" v-if="isHide" @click="isHide=!isHide">
<ys-modal-component
v-if="!isHide"
modal-title="溫馨提示"
ok-btn="確認(rèn)購買"
cancel-btn="去意已決"
@on-ok="ok"
@on-cancel="cancel"
>
<div slot="modal-content">
尊敬的用戶,您購買的商品將于支付成功后3-7個(gè)工作日內(nèi)發(fā)貨,敬請(qǐng)周知。祝您購物愉快!
</div>
</ys-modal-component>
</div>
<script>
/*
props:
modalTitle: 彈窗標(biāo)題
okBtn: 確認(rèn)按鈕
cancelBtn: 取消按鈕
注意事項(xiàng):傳參時(shí)候使用烤串的書寫方式xx-xxx
slot:
modal-content: 內(nèi)容區(qū)域
modal-footer: 頁腳按鈕區(qū)域
methods:
okHandle: 觸發(fā)確認(rèn)on-ok自定義事件
cancelHandle: 觸發(fā)取消on-cancel自定義事件
*/
Vue.component('ys-modal-component', {
props: {
modalTitle: {
type: String,
default: '標(biāo)題區(qū)域'
},
okBtn: {
type: String,
default: '確認(rèn)'
},
cancelBtn: {
type: String,
default: '取消'
}
},
template: `
<div class="modal">
<div class="modal-header">
<h4>{{ modalTitle }}</h4>
</div>
<div class="modal-content">
<div>
<slot name="modal-content">內(nèi)容區(qū)域</slot>
</div>
</div>
<div class="modal-footer">
<input class="btn blue" type="button" v-model="okBtn" @click="okHandle" />
<input class="btn" type="button" v-model="cancelBtn" @click="cancelHandle" />
</div>
</div>
`,
methods: {
okHandle () {
console.log("點(diǎn)擊確定");
this.$emit("on-ok");
},
cancelHandle () {
console.log("點(diǎn)擊取消");
this.$emit("on-cancel");
}
}
})
new Vue({
el: "#app",
data: {
isHide: false
},
methods: {
ok () {
alert("歡迎您購買本產(chǎn)品");
},
cancel () {
this.isHide = !this.isHide;
}
}
})
</script>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue3關(guān)鍵字高亮指令的實(shí)現(xiàn)詳解
這篇文章主要為大家詳細(xì)介紹了vue3實(shí)現(xiàn)關(guān)鍵字高亮指令的相關(guān)資料,w文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考一下2023-11-11
Vue實(shí)現(xiàn)virtual-dom的原理簡(jiǎn)析
這篇文章主要介紹了Vue實(shí)現(xiàn)virtual-dom的原理簡(jiǎn)析,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
vue 實(shí)現(xiàn)類似淘寶星級(jí)評(píng)分的示例
下面小編就為大家分享一篇vue 實(shí)現(xiàn)類似淘寶星級(jí)評(píng)分的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03
elementui[el-table]toggleRowSelection默認(rèn)多選事件無法選中問題
這篇文章主要介紹了elementui[el-table]toggleRowSelection默認(rèn)多選事件無法選中問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
Element中el-select下拉框?qū)崿F(xiàn)選中圖標(biāo)并回顯圖標(biāo)
本文主要介紹了Element中el-select下拉框?qū)崿F(xiàn)選中圖標(biāo)并回顯圖標(biāo),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-12-12
Vue數(shù)據(jù)更新頁面卻沒有更新的幾種情況以及解決方法
我們?cè)陂_發(fā)過程中會(huì)碰到數(shù)據(jù)更新,但是頁面卻沒有更新的情況,下面這篇文章主要給大家介紹了關(guān)于Vue數(shù)據(jù)更新頁面卻沒有更新的幾種情況以及解決方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06

