ホームページ  >  記事  >  ウェブフロントエンド  >  vue+iview でポップアップ ボックスを作成する方法 (詳細なチュートリアル)

vue+iview でポップアップ ボックスを作成する方法 (詳細なチュートリアル)

亚连
亚连オリジナル
2018-06-22 15:57:424690ブラウズ

この記事では主にvue+iviewでポップアップボックスを書くサンプルコードを紹介していますが、編集者がとても良いと思ったので、参考として共有させていただきます。エディターをフォローして見てみましょう。

iView は Vue.js に基づくオープン ソース UI コンポーネント ライブラリのセットで、主に PC インターフェイス用のミッドエンド製品とバックエンド製品を提供します。

1. iViewの特徴

1) 高品質、豊富な機能
2) フレンドリーなAPI、自由で柔軟なスペースの使用
3) 繊細で美しいUI
4) 詳細なドキュメント
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>

会社のプロジェクトの必要性により、現在 vue+iview を使用してプロジェクトを構築しています。 1.0. iview ポップアップ ボックスを使用する場合、最初にポップアップ ボックス内のフォームを検証する必要があり、iview ポップアップの [OK] ボタンをクリックした場合にのみバックグラウンド インターフェイスが呼び出されます。ボックスをクリックすると、ポップアップ ボックスが消えます。なぜですか? はい、効果を実現するために、さまざまな情報を読みました。最終的な解決策は次のとおりです。

<template> 
  <!--取消订单弹框和老板批准弹框--> 
   <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;">授权码</i-col> 
      <i-col span="6"> 
       <input class="ivu-input errorInput" type="number" v-model="code" placeholder="请输入" @blur="codeBlur"> 
       <p class="fade-transition ivu-form-item-error-tip error" style="display:none;position: static">验证码错误</p> 
      </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 &#39;jo&#39; 
  export default { 
    props:["show"], 
    data(){ 
      return { 
        loading:true, 
        loadingBtn:false,//点击申请取消按钮后loading 
        btnText:&#39;申请取消订单&#39;, 
        code:"",//验证码 
        clearTime:"",//定时器 
        countDownIndex:60,//60秒倒计时 
      } 
    }, 
    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(){ 
          //调用发送验证码接口 
   //      let operName = window.sessionStorage.getItem("userName") 
            // accountService.recommenderGetCode(operName,this.selectDelteOne.recommender,1) 
          this.countDown()   
 
      }, 
      countDown(){ 
          //倒计时 
          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 = "发送" 
                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(&#39;sdasda&#39;+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>

一般的な考え方は、最初に変数の読み込みを指定することです。これは true である必要があります。次に、ポップアップ ボックスの送信ボタンをクリックするときに、loading を false に設定し、

this.$nextTick(() => { this.loading = true;}); を追加する必要があります。効果、具体的な実装原則、この落とし穴に遭遇した場合は、最初に記録してください

ポータル -->https://github.com/iview/iview/issues/597#issuecomment-292422473

上記は私がコンパイルしたものです将来すべての人にとって役立つことを願っています。

関連記事:

nodejsでOAuth2.0認可サービスの認証を実装する方法

JSで掲示板機能を実装する方法

jsで祝日を決める方法

以上がvue+iview でポップアップ ボックスを作成する方法 (詳細なチュートリアル)の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。