# Vue.js: Watch ###### tags: `Vue` Watch 可讓我們監視某個值,當這個值變動的時候,就去做某些事情。 ``` var vm = new Vue({ el: '#app', delimiters: ['${', '}'], data: { userName: '', errMsg: '' }, watch: { userName: function(value) { if(this._valid(value)) { this.errMsg = '使用者名稱開頭不可為數字。' } else { this.errMsg = '合法的使用者名稱。'; } } }, methods: { _valid: function(name) { return /^[0-9]/.test(name); } } }); ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up