javascript - The value of an object with -ob- attribute in vue cannot obtain its other attribute values
ringa_lee
ringa_lee 2017-05-19 10:39:20
0
3
1125


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_lee
ringa_lee

ringa_lee

reply all(3)
習慣沉默

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

巴扎黑

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:

大家讲道理
var json = JSON.stringify(JSON.parse(this.list));
console.log(json);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!