-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Closed
Description
Vue.js version
1.0.21
Reproduction Link
http://www.webpackbin.com/4JE1cYtyW
Steps to reproduce
- watch an array by putting it in the
data
property - Make the template display the array
- remove an element using
Array.prototype.splice.call(this.arr, 0)
What is Expected?
- The first element of the array is removed from the view
What is actually happening?
- The first element is removed from the array but not from the view
Explanation
I read the source code from the observing feature of vue. As far as I understood Vue intercept calls to methods. Using Array.prototype
make this strategy fail (it would work with the dirty check in Angular 1.x
for example). I know it will not be easily fixable nor it's a good practice to use Array.prototype
. But actually it's how lodash
is implemented (I found this "bug" when using lodash) And I this kind of library is very widely used.
Intent to fix
Maybe we could fix it by doing this ?
const originalSplice = Array.prototype.splice;
Array.prototype.splice = function() {
if (this && this.length) {
this.splice(arguments)
} else {
originalSplice.apply(this, arguments)
}
}
Metadata
Metadata
Assignees
Labels
No labels