开发中遇到的bug-Property or method “xxxx“ is not defined on the instance but referenced during render.

method没加s加上就好了

<body>
    <div id="app">
        <button @click="sub">-</button>
        <span>{
     {
     code}}</span>
        <button @click="add">+</button>
    </div>
    <script>
        var app = new Vue({
     
            el: "#app",
            data: {
     
                code: 0
            },
            methods: {
     
                add: function () {
     
                    if (this.code < 10) {
     
                        this.code++;
                    } else {
     
                        alert('到头啦!不要再加啦');
                    }
                },
                sub: function () {
     
                    if (this.code > 0) {
     
                        this.code--;
                    } else {
     
                        alert('到头啦!不要再减啦');
                    }
                }
            }
        })
    </script>
</body>

你可能感兴趣的:(开发bug合集,vue,js)