Vue系列

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

2018-09-19  本文已影响0人  Rosa_Lv

官网上这样说:


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>
上一篇下一篇

猜你喜欢

热点阅读