hongfu
January 2, 2019, 5:25am
1
Hi,all.
A weird questions beset me!
There is a phenomenon flickering in and out.
I defined data for App as root data
data:{
user: 'Guest',
}
In other page(route via router component) i can modified the data via
root.user = {
user: ‘User 1’,
}
or via
root.user.user=‘User 1’;
if i called app.request for ajax, i can modified the data via
success: function(){ root.user.user=‘User 1’;}
Buuuuut i can not modified the data via
success: function(){
root.user = { user:‘User 1’ };
}
WHY…
hongfu
January 2, 2019, 7:46am
2
I made some test.
Result was
$root.data
{
user: ‘guest’
}
When i modified $root.data via
var self = this;
var d = this.$root;
…
success: function(){
d.user = { user:‘User 1’ };
console.log(d.user);// {user: ‘Guest’}
console.log(self.$root.user);// {user: ‘User 1’}
}
the question appear clearly.
but i still do not understand,Why?
Bc i still don’t understand type proxy?
$root
is so called proxy JS object that dynamically combines app’s root data and methods. So to modify and work with it correctly, you need to always reference it as this.$root
. Or you can just modify the data directly like this.$app.data.user = ...
hongfu
January 3, 2019, 3:49am
4
thanks. even i don‘t see clearly about proxy obj.