2023-01-02_Vue属性监听器

2023-01-01  本文已影响0人  微笑碧落

前言

1. 属性监听器的使用

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Vue3 Demo</title>
    </head>
    <body>
        <div style="text-align: center;" id="App">
            <input v-model="searchText"/>
        </div>

        <script src="vue.global.js"></script>

        <script>
            const App = {
                data(){
                    return {
                        searchText : "",
                    }
                },
                methods: {
                },
                watch: {
                    searchText(oldValue, newValue){
                        if(oldValue.length > 10){
                            console.log("文本太长了")
                        }
                    }
                }
            }
            let inst = Vue.createApp(App).mount("#App");
        </script>
    </body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读