Home  >  Q&A  >  body text

javascript - The value of an object with -ob- attribute in vue cannot obtain its other attribute values


The object passed in by the play method cannot obtain its properties

Can only print to this object and its value It cannot be printed or obtained. This object has an additional --ob-- attribute. After checking the information, it is said that the object is monitored by vue

. What is printed is In this way, printing its properties will be undefined

通过什么方法才可以拿到paly方法中参数的属性?
ringa_leeringa_lee2711 days ago1127

reply all(3)I'll reply

  • 習慣沉默

    習慣沉默2017-05-19 10:41:20

    In order to achieve two-way binding, Vue packages all properties into getters and setters.
    If you want to print directly, just print the properties directly.
    Or you can directly click on the... behind the property name in devtools and the current value will be found. Note that what is displayed when clicking is the current value when clicking, not necessarily the value when printing. If timeliness is required, it is better to print the corresponding attributes directly

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-19 10:41:20

    Or can the poster provide a specific definition of the play method?

    In addition, I wrote a simple demo:

    <!DOCTYPE html>
    <html>
    <head>
      <title>Welcome to Vue</title>
      <script src="https://unpkg.com/vue/dist/vue.js"></script>
    </head>
    <body>
      <p id="app">
        <ul>
          <li v-for="(item, index) in list" @click="test(item)">{{ item.name }}</li>
        </ul>
      </p>
    
      <script>
        new Vue({
          el: '#app',
          data: {
            list: [{
              name: 'A',
              sex: 'male'
            }, {
              name: 'B',
              sex: 'female'
            }, {
              name: 'C',
              sex: '???'
            }]
          },
          methods: {
            test(item) {
              console.log(item);
              console.log(item.name);
            }
          }
        })
      </script>
    </body>
    </html>

    Click A, and the object of A and the name attribute of A are output in the console:

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:41:20

    var json = JSON.stringify(JSON.parse(this.list));
    console.log(json);

    reply
    0
  • Cancelreply