小程序修改 object中的array数据项不使用setData也会直接修改内存的源对象?
基础库:2.9.4
代码
JS
Page({ /** * 页面的初始数据 */ data: { formData:{ test:[1,2], test1:'哈哈哈' } }, handleSubmit(){ let self = this, params = { test: this.data.formData.test, test1:this.data.formData.test1 } console.log(params) console.log(this.data.formData) //params = {"test":[1,2],"test1":"哈哈哈"} formData = {"test":[1,2],"test1":"哈哈哈"} success params.test[0] = '哈哈哈';
console.log(params) console.log(this.data.formData) //params = {"test":["哈哈哈",2],"test1":"哈哈哈"} formData = {"test":["哈哈哈",2],"test1":"哈哈哈"} ??? } }) |
为什么会直接把内存的源对象给修改了???????