changing one element's value also changes elements with the same index in all rows
Version
3.2.0-beta.1
Reproduction link
[https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8ZGl2IHYtZm9yPVwiKHJvdyx5KSBpbiBsaXN0XCI XG4gICAgPGRpdj5cbiAgICAgIC0tLSByb3cge3t5fX1cbiAgICA8L2Rpdj5cbiAgICA8ZGl2IHYtZm9yPVwiKG51bSx4KSBpbiByb3dcIiBAY2xpY2s9XCJoYW5kbGVDbGljayh4LHkpXCI XG4gICAgICB7e251bX19XG4gICAgPC9kaXY XG4gIDwvZGl2PlxuICBjbGljayAnMCcgYWJvdmVcbjwvdGVtcGxhdGU XG5cbjxzY3JpcHQgc2V0dXA XG4gaW1wb3J0IHtyZWZ9IGZyb20gJ3Z1ZSdcbiAgY29uc3QgbGlzdCA9IHJlZihuZXcgQXJyYXkoNCkuZmlsbChuZXcgQXJyYXkoNCkuZmlsbCgwKSkpXG4gIFxuICBjb25zdCBoYW5kbGVDbGljayA9ICh4LHkpPT57XG4gICAgbGlzdC52YWx1ZVt5XVt4XSA9IDFcbiAgfVxuICBcbiA8L3NjcmlwdD4ifQ==](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8ZGl2IHYtZm9yPVwiKHJvdyx5KSBpbiBsaXN0XCI XG4gICAgPGRpdj5cbiAgICAgIC0tLSByb3cge3t5fX1cbiAgICA8L2Rpdj5cbiAgICA8ZGl2IHYtZm9yPVwiKG51bSx4KSBpbiByb3dcIiBAY2xpY2s9XCJoYW5kbGVDbGljayh4LHkpXCI XG4gICAgICB7e251bX19XG4gICAgPC9kaXY XG4gIDwvZGl2PlxuICBjbGljayAnMCcgYWJvdmVcbjwvdGVtcGxhdGU XG5cbjxzY3JpcHQgc2V0dXA XG4gaW1wb3J0IHtyZWZ9IGZyb20gJ3Z1ZSdcbiAgY29uc3QgbGlzdCA9IHJlZihuZXcgQXJyYXkoNCkuZmlsbChuZXcgQXJyYXkoNCkuZmlsbCgwKSkpXG4gIFxuICBjb25zdCBoYW5kbGVDbGljayA9ICh4LHkpPT57XG4gICAgbGlzdC52YWx1ZVt5XVt4XSA9IDFcbiAgfVxuICBcbiA8L3NjcmlwdD4ifQ==)
Steps to reproduce
click 0
What is expected?
the clicked 0 changes to 1
What is actually happening?
0 with the same index in all rows change to 1
If the first parameter is an object, each slot in the array will reference that object.
// Objects by reference.
var arr = Array(3).fill({}) // [{}, {}, {}];
// 需要注意如果fill的参数为引用类型,会导致都执行都一个引用类型
// 如 arr[0] === arr[1] 为true
arr[0].hi = "hi"; // [{ hi: "hi" }, { hi: "hi" }, { hi: "hi" }]
If the first parameter is an object, each slot in the array will reference that object.
you are right, thx