2.5.13
https://jsfiddle.net/49gptnad/905/
Just run it and open the console in a debugger
that the target variable is type checked for being a string before trying to perform the key in target line, to prevent a big error message
a big error message comes up
I'm going to have a look at a fix for it now so I'll post it if I figure it out
So I believe that this fix is appropriate. Because you are setting on a string, which you can do.. but really actually can't.
String variables seem a bit.............. weird
Take a look at this:
https://jsfiddle.net/49gptnad/906/
I think it's alright to simply make the code say this:
if (target.constructor !== String && key in target && !(key in Object.prototype)) {
target[key] = val
return val
} else if (target.constructor == String) {
return undefined
}
because properties set on strings are always undefined, so technically the value is being set as the value but then becoming undefined on the next tick..
as evidenced when you open a node terminal, and type let word = 'word`` and thenword.letter = 'a'` the terminal will output 'a' for some reason, and no error, and also when you console.log(word.letter = 'a'), but, straight after when you try to access this property via it's key, it will be undefined, so, I don't see any harm in returning undefined
Feel free to submit a PR that adds a warning on development mode (+ the test ofc 馃槃 )
@posva there won't be any issues with reactivity?
$set must be used on an object anyways
Yes, you can look how warnings are implemented and tested and add a warning for the set method
will look into vue ,will get ready then start working with you guys....
Hi. I have sent a pull request about this issue: #7452
According to documentation, https://vuejs.org/v2/api/#vm-set
you are supposed to be using it in this way, i think;
this.$set(this.$data, 'testObj', 'bar');
Most helpful comment
According to documentation, https://vuejs.org/v2/api/#vm-set
you are supposed to be using it in this way, i think;
this.$set(this.$data, 'testObj', 'bar');