How to use the monitor properties Vue's watch?

Requirements: I need to be able to perform data changes when a particular action , such as I enter a number in the input box 88 , the system detects later it will pop bye , while other characters will not trigger input, this demand more than simply the ox hair, in fact, this is a custom event , and click / press / scroll such events are the same, are eligible after the implementation of specific code. in vue inside, this feature requires the use of Watch .

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
  <title>Vue Test</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model:value="inputValue" />
    </div>
    <script>
        var vApp = new Vue({
            el: "#app",
            data: {
                inputValue: ''
            }
        })
        // $watch 需要在 new Vue({}) 之外声明.
        vApp.$watch("inputValue", function(newValue, oldValue){
            console.log(newValue);
            if (newValue === "88") { alert("拜拜"); }
        })
    </script>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/aisowe/p/11431002.html