如下所示:
十余年的臨猗網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)整合營(yíng)銷(xiāo)推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整臨猗建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“臨猗網(wǎng)站設(shè)計(jì)”,“臨猗網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

首先我們需要?jiǎng)?chuàng)建 confirm.vue , confirm.js這兩個(gè)文件,一個(gè)實(shí)現(xiàn)dom結(jié)構(gòu),一個(gè)實(shí)現(xiàn)相關(guān)邏輯
confirm.vue
<template>
<div class="confirm" v-if="isShow">
<div class="con_box" >
<div class="context">
<h7>{{text.type}}</h7>
<p>{{text.msg}}</p>
<div class="btn">
<span @click="close()" v-if="text.btn.no">{{text.btn.no}}</span>
<span @click="ok()" v-if="text.btn.ok">{{text.btn.ok}}</span>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data(){
return{
isShow:true,
text:{
type:'提示',
msg:'確定刪除此條信息?',
btn:{
ok:'確定',
no:'取消'
},
}
}
},
methods:{
close(){
console.log('關(guān)閉');
},
ok(){
console.log('確定')
}
}
}
</script>
<style scoped>
.confirm{background-color:rgba(0, 0, 0, 0.6);width: 100%;height: 100%; position: fixed;top: 0;}
.con_box{width: 75%;height: 22%;background-color: white;position: absolute;top: 0;bottom: 0;left: 0;right: 0;margin: auto;border-radius: 5px;}
.context{padding: 10px;}
.context h7{font-size: 24px;padding: 15px;}
.context p{font-size: 20px;padding: 35px 15px;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;}
.btn{padding: 15px;text-align: right;}
.btn span{padding: 10px 35px; color: white;border-radius: 5px;}
.btn span:nth-child(1){background-color: #f1f1f1;color: rgb(106, 223, 223);}
.btn span:nth-child(2){background-color: rgb(106, 223, 223);}
</style>confirm.js
import Vue from 'vue';
import confirm from './confirm.vue';
let confirmConstructor = Vue.extend(confirm);
let theConfirm = function (text) {
return new Promise((res, rej) => { //promise封裝,ok執(zhí)行resolve,no執(zhí)行rejectlet
let confirmDom = new confirmConstructor({
el: document.createElement('div')
})
document.body.appendChild(confirmDom.$el); //new一個(gè)對(duì)象,然后插入body里面
confirmDom.text = text; //為了使confirm的擴(kuò)展性更強(qiáng),這個(gè)采用對(duì)象的方式傳入,所有的字段都可以根據(jù)需求自定義
confirmDom.ok = function () {
res()
confirmDom.isShow = false
}
confirmDom.close = function () {
rej()
confirmDom.isShow = false
}
})
}
export default theConfirm;
//暴露出去,別忘記掛載到vue的原型上
// => 在main.js里面先引入 import theConfirm from './components/confirm/confirm.js'
// => 再掛載 Vue.prototype.$confirm = theConfirm;
//在需要的地方直接用以下方法調(diào)用即可:
// this.$confirm({
// type:'提示',
// msg:'是否刪除這條信息?',
// btn:{
// ok:'yes',
// no:'no'
// }
// }).then(() => {
// console.log('ok')
// })
// .catch(() => {
// console.log('no')
// })
main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
//這里就是對(duì)組件的綁定
import theConfirm from './components/confirm/confirm.js'
Vue.prototype.$confirm = theConfirm;
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
helloworld.vue
<template>
<div class="hello">
<span @click="handMe()">點(diǎn)擊一下</span>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
}
},
methods:{
handMe(){
this.$confirm({
type:'提示',
msg:'是否刪除這條信息?',
btn:{
ok:'yes',
no:'no'
}
}).then(() => {
console.log('ok')
})
.catch(() => {
console.log('no')
})
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
span{font-size: 24px;}
</style>
以上這篇vue封裝可復(fù)用組件confirm,并綁定在vue原型上的示例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持創(chuàng)新互聯(lián)。
新聞名稱:vue封裝可復(fù)用組件confirm,并綁定在vue原型上的示例
本文網(wǎng)址:http://chinadenli.net/article48/ipschp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、做網(wǎng)站、網(wǎng)站策劃、Google、虛擬主機(jī)、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
網(wǎng)頁(yè)設(shè)計(jì)公司知識(shí)