Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue.set Api strange behavior if path is a numerical string #5884

Closed
TheDadycool opened this issue Jun 14, 2017 · 3 comments
Closed

Vue.set Api strange behavior if path is a numerical string #5884

TheDadycool opened this issue Jun 14, 2017 · 3 comments

Comments

@TheDadycool
Copy link

TheDadycool commented Jun 14, 2017

Version

2.3.4

Reproduction link

https://jsfiddle.net/v0dbnvv0/1/

Steps to reproduce

Vue.set(array, "indexInTheArrayInString", value) is not working as expected compare to Vue.set(array, "indexInTheArrayInNumericForm", value)

What is expected?

Both version working the same i suppose?

What is actually happening?

Watcher on the value are not triggered even if the value is correctly changed in the model


My currently fixed in my code:
export function AdvVueSet(obj, path, value) {
if (!isNaN(path)) {
path = +path;
}
Vue.set(obj, path, value);
}

@defcc
Copy link
Member

defcc commented Jun 14, 2017

I think maybe there should be an improvement, as we could access and assign array item via string type index. In fact, a[1] is equal to a['1']. Refer http://www.ecma-international.org/ecma-262/5.1/#sec-15.4

We could check the key, and try to convert it to a number type.

if (Array.isArray(target) && typeof key === 'number') {

@yyx990803
Copy link
Member

Probably just check if the string is an integer because it has to be an index.

@defcc
Copy link
Member

defcc commented Jun 16, 2017

Thanks @Peter-WF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants