vue+iview寫個(gè)彈框的示例代碼
iView 是一套基于Vue.js的開源UI組件庫(kù),主要服務(wù)于PC界面的中后臺(tái)產(chǎn)品。
1、iView的特性
1) 高質(zhì)量、功能豐富
2) 友好的API ,自由靈活地使用空間
3) 細(xì)致、漂亮的 UI
4) 事無(wú)巨細(xì)的文檔
5) 可自定義主題
2、iView的安裝:
1) 使用npm:
npm install --save iview
2) CDN引入:
<link rel="stylesheet" href="css/iview.css" rel="external nofollow" > <script src="js/iview.min.js"></script>
由于公司項(xiàng)目需要,所以目前搗鼓了vue+iview搭建了一個(gè)項(xiàng)目,用的環(huán)境都是1.0版本,在使用iview彈框中,由于需要先進(jìn)行彈框中表單的驗(yàn)證,驗(yàn)證通過(guò)才調(diào)用后臺(tái)接口,但是呢,iview彈框中的確定按鈕點(diǎn)擊一下彈框就消失了,怎么辦,要實(shí)現(xiàn)效果,各種翻看資料,最終解決辦法如下:
<template>
<!--取消訂單彈框和老板批準(zhǔn)彈框-->
<Modal
:visible.sync="show"
title="提示"
:loading="loading"
@on-ok="asyncOK">
<Row>
<i-col span="3"></i-col>
<i-col span="1" style="color:red;margin-top:7px;font-weight: bold">*</i-col>
<i-col span="2" style="margin-top:5px;">授權(quán)碼</i-col>
<i-col span="6">
<input class="ivu-input errorInput" type="number" v-model="code" placeholder="請(qǐng)輸入" @blur="codeBlur">
<div class="fade-transition ivu-form-item-error-tip error" style="display:none;position: static">驗(yàn)證碼錯(cuò)誤</div>
</i-col>
<i-col span="3" style="margin-left:5px;">
<i-button type="primary" :loading="loadingBtn" @click="toLoading">
<span v-if="!loadingBtn">{{btnText}}</span>
<span v-else>{{btnText}}</span>
</i-button>
</i-col>
</Row>
</Modal>
</template>
<script type="text/javascript">
import {
orderService
} from 'jo'
export default {
props:["show"],
data(){
return {
loading:true,
loadingBtn:false,//點(diǎn)擊申請(qǐng)取消按鈕后loading
btnText:'申請(qǐng)取消訂單',
code:"",//驗(yàn)證碼
clearTime:"",//定時(shí)器
countDownIndex:60,//60秒倒計(jì)時(shí)
}
},
methods:{
codeBlur(){
if(this.code == ""){
$(".errorInput").css("border","1px solid red")
$(".error").css("display","block")
}else{
$(".errorInput").css("border","1px solid #d7dde4")
$(".error").css("display","none")
}
},
toLoading(){
//調(diào)用發(fā)送驗(yàn)證碼接口
// let operName = window.sessionStorage.getItem("userName")
// accountService.recommenderGetCode(operName,this.selectDelteOne.recommender,1)
this.countDown()
},
countDown(){
//倒計(jì)時(shí)
var that = this;
that.loadingBtn = true
that.btnText = that.countDownIndex+"秒"
that.countDownIndex--;
that.clearTime = setInterval(function(){
console.log(that.countDownIndex)
if(that.countDownIndex == 0){
that.countDownIndex = 60
that.btnText = "發(fā)送"
that.loadingBtn = false
window.clearTimeout(that.clearTime)
return false
}
that.btnText = that.countDownIndex+"秒"
that.countDownIndex--;
},1000)
// }
},
asyncOK(){
//提交
if(this.code == ""){
this.show = true
console.log('sdasda'+this.show)
$(".errorInput").css("border","1px solid red")
$(".error").css("display","block")
this.loading = false
this.$nextTick(() => { this.loading = true;});
return
}
this.$nextTick(() => {this.loading = true; });
// let operId = window.sessionStorage.getItem("crmUserId")
// let operName = window.sessionStorage.getItem("userName")
// if(this.isApply){
// orderService.sendSingleUpdate03(this.data, 3, operName, operId, this.code).then(res => this.updateList(res.message))
// }else{
// orderService.sendSingleUpdate03(this.data, 2, operName, operId, this.code).then(res => this.updateList(res.message))
// }
}
}
}
</script>
大概思路就是先命名一個(gè)變量loading,這里必須為true,然后在點(diǎn)擊彈框的提交按鈕的時(shí)候先把loading設(shè)置為false,然后必須加上
this.$nextTick(() => { this.loading = true;});就能實(shí)現(xiàn)效果啦,具體實(shí)現(xiàn)原理,這坑遇到了,就先記錄下來(lái)
傳送門-->https://github.com/iview/iview/issues/597#issuecomment-292422473
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
如何在Vue項(xiàng)目中應(yīng)用TypeScript類
與如何在React項(xiàng)目中應(yīng)用TypeScript類類似在VUE項(xiàng)目中應(yīng)用typescript,我們需要引入一個(gè)庫(kù)vue-property-decorator,需要的小伙伴可續(xù)看下文具體介紹2021-09-09
Vue使用antd組件a-form-model實(shí)現(xiàn)數(shù)據(jù)連續(xù)添加功能
這篇文章主要介紹了Vue使用antd組件a-form-model實(shí)現(xiàn)數(shù)據(jù)連續(xù)添加功能,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-12-12
django簡(jiǎn)單的前后端分離的數(shù)據(jù)傳輸實(shí)例 axios
這篇文章主要介紹了django簡(jiǎn)單的前后端分離的數(shù)據(jù)傳輸實(shí)例 axios,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05
vue3動(dòng)態(tài)路由addRoute實(shí)例詳解
這篇文章主要介紹了vue3動(dòng)態(tài)路由addRoute的相關(guān)知識(shí),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09
利用Vue3 (一)創(chuàng)建Vue CLI 項(xiàng)目
這篇文章主要介紹利用Vue3 創(chuàng)建Vue CLI 項(xiàng)目,下面文章內(nèi)容附有官方文檔鏈接,安裝過(guò)程,需要的可以參考一下2021-10-10

