zoukankan      html  css  js  c++  java
  • computed计算属性依赖的响应式属性为对象obj时,对象obj中有属性字段【A、B、C】时,对A、B进行了if判断,那么只有A、B变化时,计算属性才更新,否则不更新

    computed计算属性依赖的响应式属性为对象obj时,对象obj中有属性字段【A、B、C】时,对A、B进行了if判断,那么只有A、B变化时,计算属性才更新,否则不更新

    注意并不是obj变化时,omputed计算属性就更新;而是obj中对应computed计算属性依赖的相应属性【A、B】变化时才会更新
    点击onSubmitA,才会触发监听formData;
    点击onSubmitB,不会触发监听formData;
    <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="onSubmitA">a++</el-button>
          <el-button type="primary" @click="onSubmitB">b++</el-button>
        </el-form-item>
      </el-form>
    
    </template>
    <script>
    export default {
      name: 'couponForm',
      computed: {
        formData () {
          return {
            a: this.form.a,
            b: 1
          }
        }
      },
      watch: {
        formData: {
          deep: true,
          handler (newVal, oldVal) {
            console.log('newVal', newVal)
            console.log('oldVal', oldVal)
            console.log('newVal===oldVal?', newVal === oldVal)
            console.log('newVal==oldVal?', JSON.stringify(newVal) === JSON.stringify(oldVal))
          }
        }
      },
      data () {
        return {
          form: {
            a: 1,
            b: 2
          }
    
        }
      },
      methods: {
        onSubmitA () {
          this.form.a = this.form.a + 1
        },
        onSubmitB () {
          this.form.b = this.form.b + 1
        }
      }
    }
    </script>
  • 相关阅读:
    Python -- Redis List
    Python --Redis Hash操作
    Python使用redis介绍
    缓存服务器
    linux python3获取ip地址
    Rabbitmq -- rpc
    Rabbitmq--topic
    Rabbitmq -- direct
    删除rabbitmq中持久化的队列和数据
    Exchange-fanout 广播模式
  • 原文地址:https://www.cnblogs.com/sakura-sakura/p/11132120.html
Copyright © 2011-2022 走看看