vue屬性監聽watch
阿新 • • 發佈:2021-09-20
watch和data、methods等同級
watch兩個引數(newValue,odlValue) 分別為新資料和舊資料
<!DOCTYPE html> <html> <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></title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id='app'> <input type="text" v-model='msg'> </div> <script> const vm= new Vue({ el: '#app', data: { msg:'111' }, methods: { }, // 屬性監聽 watch:{ // 兩個引數(新資料,舊資料) msg(newValue,oldvalue){ // 監聽input框變化,分別列印新資料和舊資料 console.log(newValue); console.log(oldvalue); } } })</script> </body> </html>