this.query = this.$route.query;
this.getList(this.query);
getList(data){
data.method = 'get'
}
为什么这样传值,后面我再请求this.$route.query的时候发现多了个medthod:'get'字段呢,如何解决这种问题?
this.query = this.$route.query;
this.getList(this.query);
getList(data){
data.method = 'get'
}
为什么这样传值,后面我再请求this.$route.query的时候发现多了个medthod:'get'字段呢,如何解决这种问题?
因为你调用this.getList(this.query)中传入的是引用,也就是在函数内部data.method = 'get'相当于this.query.method = 'get',也相当于this.$route.query.method = 'get'
如果单纯想使用this.$route.query中的内容而不想改变原有对象的话,可以对getList函数做一点修改:
getList ({...data}) {
data.method = 'get'
}
这里需要保证getList的参数是一个对象,方便收集到data中。
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答4.7k 阅读✓ 已解决
4 回答4.3k 阅读✓ 已解决
4 回答1.9k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
2 回答2.5k 阅读✓ 已解决
JSON.parse(JSON.stringify(this.$route.query))