<template> <el-form ref="form" :model="form" label-width="80px"> <el-form-item label="a"> <el-input v-model="form.a"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="onSubmit">a++</el-button> </el-form-item> </el-form> </template> <script> export default { name: ‘couponForm‘, computed: { formData () { return { a: this.form.a } } }, watch: { formData: { deep: true, handler (newVal, oldVal) { console.log(‘newVal‘, newVal) // {a:1} console.log(‘oldVal‘, oldVal) // {a:1} console.log(‘newVal===oldVal?‘, newVal === oldVal) // false console.log(‘newVal==oldVal?‘, JSON.stringify(newVal) === JSON.stringify(oldVal)) // true } } }, data () { return { form: { a: 1 } } }, methods: { onSubmit () { this.form.a = this.form.a + 1 this.form.a = this.form.a - 1 } } } </script>
原文:https://www.cnblogs.com/sakura-sakura/p/11131631.html