Reputation: 77
I'm working on the code at Info.vue
data() {
return {
option: [],
}
}
created() {
console.log(this.option);
}
methods: {
// I get the value from the form on change
myChange: function (name, age) {
this.option.push({name: name, age: age})
}
result :
[__ob__: Observer]
0:
name: ("zoka")
age: ("18")
__ob__: Observer {value: {…}, dep: Dep, vmCount: 0}
I can't get the value in this.option, give me an idea. Thanks
Upvotes: 0
Views: 2641
Reputation: 1920
@json see below for how best to see what you have within your data property option
. Where exactly are you trying to see your option
property? In the console logs or in your template?
<script>
export default {
data() {
return {
option: [],
};
},
watch: {
option() {
// or check in a watcher. This will fire
// anytime the `option` property is updated
console.log("option within watcher:", this.option);
},
},
methods: {
myChange(name, age) {
this.option.push({ name, age });
// you can check here if you want
console.log("option within myChange:", this.option);
},
},
created() {
// option is the default of an empty array here
console.log("option within created:", this.option);
},
};
</script>
You really should invest time into reading the Vue docs though. They've spent a lot of time putting them together and they can easily answer this question for you.
The official docs can be found here.
Read the docs and become familiar with Vue and it will become a lot more enjoyable. You'll be flying through it all in no time :)
Upvotes: 1