Fork me ([email protected])
by Ben Clayton
HTML
<script src="https://cdn.rawgit.com/vuejs/vue/v1.0.28/dist/vue.js"></script>
<div id="demo">
<div>Open console to see that watcher trigger when first or second field changes, but not the third</div>
<input type="text" v-model="first">
<input type="text" v-model="second">
<input type="text" v-model="third">
</div>
<hr/>
<ul>
<li>vue <a href="https://cdn.rawgit.com/vuejs/vue/v1.0.28/dist/vue.js">v1.0.28</a></li>
<li>
Other fiddles:
<a target="_blank" href="https://jsfiddle.net/simplesmiler/14dtfh51/">vue 2</a>,
<a target="_blank" href="https://jsfiddle.net/simplesmiler/xto1h4k4/">router</a>,
<a target="_blank" href="https://jsfiddle.net/simplesmiler/jtm8tdwg/">vuex</a>
</li>
</ul>
JavaScript
// @NOTE: define $touch method globally
Vue.mixin({
methods: {
$touch: function() {
return Date.now();
},
},
});
new Vue({
el: '#demo',
data: function() {
return {
first: 'first',
second: 'second',
third: 'third',
};
},
watch: {
'$touch(first, second)': function(a) {
console.log('first or second field has changed',a);
},
},
});