[精讚] [會員登入]
1173

vue.js modal 作兩個選項按鈕並導向不同頁面

vue.js modal 作兩個選項按鈕

分享此文連結 //n.sfs.tw/11324

分享連結 vue.js modal 作兩個選項按鈕並導向不同頁面@igogo
(文章歡迎轉載,務必尊重版權註明連結來源)
2019-10-24 16:51:31 最後編修
2017-06-17 00:19:19 By igogo
 

 

vue.js

這個情況是使用者request 另一台server 所得到的值後想以不定的選項來決定要走向哪個頁面,  因此我決定用modal , 在modal 做兩個yes or no的按鈕, 並把值以GET的方式帶到hello頁面中做處理, 其它的值是放在後端以session帶著 只是在前面要讓使用者決定怎麼走

 window.location.href = 'hello?option=' + msg; 

 

如圖

 

Mary 是session帶過來的值, 屬於在後面傳送, yes則是讓使用者在前端傳過來的值

 

關鍵在此

<button class="modal-default-button" @click="$emit('close','yes')">

 

 

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="https://unpkg.com/vue"></script>
    <title>JSP Page</title>
</head>

<body>
    <header>
        <style type="text/css">
        .modal-mask {
            position: fixed;
            z-index: 9998;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, .5);
            display: table;
            transition: opacity .3s ease;
        }
        
        .modal-wrapper {
            display: table-cell;
            vertical-align: middle;
        }
        
        .modal-container {
            width: 400px;
            height: 80px;
            margin: 0px auto;
            padding: 20px 30px;
            background-color: #fff;
            border-radius: 2px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
            transition: all .3s ease;
            font-family: Helvetica, Arial, sans-serif;
        }
        
        .modal-header h4 {
            margin-top: 0;
            color: #42b983;
        }
        
        .modal-body {
            margin: 20px 0;
        }
        /*http://www.bestcssbuttongenerator.com/*/
        
        .modal-default-button {
            float: right;
            background: #3498db;
            background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
            background-image: -moz-linear-gradient(top, #3498db, #2980b9);
            background-image: -ms-linear-gradient(top, #3498db, #2980b9);
            background-image: -o-linear-gradient(top, #3498db, #2980b9);
            background-image: linear-gradient(to bottom, #3498db, #2980b9);
            -webkit-border-radius: 10;
            -moz-border-radius: 10;
            border-radius: 10px;
            font-family: Georgia;
            color: #ffffff;
            font-size: 15px;
            padding: 8px 9px 9px 8px;
            border: solid #1f628d 1px;
            text-decoration: none;
        }
        /*
                     * The following styles are auto-applied to elements with
                     * transition="modal" when their visibility is toggled
                     * by Vue.js.
                     *
                     * You can easily play with the modal transition by editing
                     * these styles.
                     */
        
        .modal-enter {
            opacity: 0;
        }
        
        .modal-leave-active {
            opacity: 0;
        }
        
        .modal-enter .modal-container,
        .modal-leave-active .modal-container {
            -webkit-transform: scale(1.1);
            transform: scale(1.1);
        }
        </style>
    </header>
    <!-- template for the modal component -->
    <script type="text/x-template" id="modal-template">
        <transition name="modal">
            <div class="modal-mask">
                <div class="modal-wrapper">
                    <div class="modal-container">
                        <div class="modal-header">
                            <slot name="header">
                            </slot>
                        </div>
                        <div class="modal-footer">
                            <slot name="footer">
                                <button class="modal-default-button" @click="$emit('close','yes')">
                                    YES
                                </button>
                                <button class="modal-default-button" @click="$emit('close','no')">
                                    NO
                                </button>
                            </slot>
                        </div>
                    </div>
                </div>
            </div>
        </transition>
    </script>
    <!-- app -->
    <div id="app">
        
        <!-- use the modal component, pass in the prop -->
        <modal v-if="showModal" @close="say">
            <!--
                  you can use custom content here to overwrite
                  default content
                -->
            <h4 slot="header">YES or NO</h4>
        </modal>
    </div>
    <script>
    // register modal component
    Vue.component('modal', {
        template: '#modal-template'

    })

    // start app
    new Vue({
        el: '#app',
        data: {
            showModal: true
        },
        methods: {
            say: function(msg) {
                console.log(msg);
                this.showModal = false;
                window.location.href = 'hello?option=' + msg;
            }
        }
    })
    </script>
</body>

</html>

 

END

你可能感興趣的文章

[vue.js] 動態的props 做parent-child components 雙向綁定 vue.js props components camel-case

將google試算表當作簡易資料庫,利用Google apps cript 在網頁上操作查詢 將google試算表當作簡易資料庫,利用apps cript 在網頁上操作查詢 若我有一試算表資料 縣市 status

[javascript] 將角色物件放到清單中,並依序讀出每個角色的X值 參考在scratch中建立三個角色並且給定值 http://n.sfs.tw/content/index/14716 一

題庫批次匯入google表單 請先建一新試算表, 將題目轉成格式如下 並將網址列記下來, 後續的題目就是從此試算表讀出 題目 答案 選項一 選項二 選

vue.js components 多個組件的呈現 vue.js 組件 component

vue.js modal 作兩個選項按鈕並導向不同頁面 vue.js modal 作兩個選項按鈕

隨機好文

編碼的順序 utf8 big5

臺中市雲端校務系統與Windows AD帳號整合(6) 修改Windows AD 密碼原則

雲端校務系統與OPENLDAP帳號整合(1) 本文件目標是為做單一帳號整合, 使用校端更改密碼服務, 將雲端校務系統的帳密同步至校內LDAP server, 並讓SA

刪除資料夾內的檔案 lambda 一行文 Arrays.stream(new File("/folder/path").

[javascript] 將角色物件放到清單中,並依序讀出每個角色的X值 參考在scratch中建立三個角色並且給定值 http://n.sfs.tw/content/index/14716 一