1. 程式人生 > 程式設計 >使用Vant完成Dialog彈框案例

使用Vant完成Dialog彈框案例

效果展示:

使用Vant完成Dialog彈框案例

完整程式碼:

<template>
 <!-- 完成Dialog 彈框 -->
 <div id="dialog">
  <van-button class="btn" type="primary" @click="TipDialog">提示彈出框</van-button>
  <van-button class="btn" type="primary" @click="Dialog">(確認、取消)的彈出框</van-button>
 </div>
</template>
 
<script>
 export default{
  data(){
   return{
    msg:''
   }
  },methods:{
    // 提示彈出框
   TipDialog(){
    this.$dialog.alert({
      // title:'標題呀',message:'彈框內容'
    }).then(()=>{
     console.log('點選了確認')
    })
   },//(確認、取消)的彈出框
   Dialog(){
    this.$dialog.confirm({
     title:'標題奧',message:'哈哈哈哈,嗯嗯,Just do it',confirmButtonColor:'red'
    }).then(()=>{
     console.log('點選了確認')
    }).catch(()=>{
     console.log('點選了取消')
    })
   }
 
  },mounted() {
 
  }
 }
</script>
 
<style>
 .btn{
  margin:20px;
 }
</style>

Dialog的相關API和Options參考:Dialog的相關API和Options詳見

補充知識:van-dialog 彈出框之元件呼叫小結 - Vue

van-dialog 彈出框之元件呼叫方法小結,結合一些 api 中提供的屬性進行組合搭配後的效果。

使用Vant完成Dialog彈框案例

html

<button type="button" style="width: 100px; height: 30px;" @click="remarksPaperClick">備註</button>
<van-dialog v-model="dialogShow" :show-cancel-button="true" :before-close="beforeClose">
  <div style="width: 100%; height: 200px; display: flex; flex-direction: column; align-items: center;">
  <span style="width: 100%; height: 30px; font-size: 20px; color: #ffffff; font-weight: bold; text-align: center; background-color: #37AAEA;">備註</span>
  <van-field
    v-model="remarkValue"
    placeholder="請輸入備註內容"
    clearable
    autosize
    type="textarea"
    rows="1"
    maxlength="230"
    show-word-limit
  />
  </div>
</van-dialog>

js

remarksExamClick :function (item) { // 點選事件 - 是否載入備註框元件 - 題目備註
  console.log(item);
},beforeClose : function (action,done) { // 點選事件 - 備註按鈕提示框
  if (action === 'confirm') { // 確認
   console.log('[點選事件 - 備註] - 確認');
 
   done(); // 關閉提示框
  } else if (action === 'cancel') { // 取消
   console.log('[點選事件 - 備註] - 取消');
   done(); // 關閉提示框
  }
},

css 樣式根據實際業務場景需求自由配置即可。

以上這篇使用Vant完成Dialog彈框案例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。