美文网首页Vue系列
关于vue button disabled属性需要注意的地方

关于vue button disabled属性需要注意的地方

作者: Rosa_Lv | 来源:发表于2018-09-19 10:08 被阅读0次

    官网上这样说:


    QQ截图20180919095544.png

    经测试,disabled无效的情况(按钮可点击)为 null、undefined、false,空字符串是生效的,在开发时需要注意。

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>vue button disabled</title>
        <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
    </head>
    
    <body>
        <div id="app">
            <button class="btn" :disabled="isButtonDisabled">hello</button>
            <button class="btn" @click="isButtonDisabled = false">flase</button>
            <button class="btn" @click="isButtonDisabled = null">null</button>
            <button class="btn" @click="isButtonDisabled = undefined">undefined</button>
            <button class="btn" @click="isButtonDisabled = true">true</button>
            <button class="btn" @click="isButtonDisabled = '123'">非空字符串</button>
            <button class="btn" @click="isButtonDisabled = ''">空字符串</button>
            <button class="btn" @click="isButtonDisabled = 0">数字0</button>
            <button class="btn" @click="isButtonDisabled = []">空数组</button>
            <button class="btn" @click="isButtonDisabled = {}">空数组</button>
        </div>
    
        <script>
            var vm = new Vue({
                el: '#app',
                data: {
                    isButtonDisabled: false,
                }
            })
        </script>
    </body>
    
    </html>
    

    相关文章

      网友评论

        本文标题:关于vue button disabled属性需要注意的地方

        本文链接:https://www.haomeiwen.com/subject/kcusgftx.html