在跟后端交互的时候传参key值的问题,入股不需要的情况下如何删除key

如果this.priceType是空就不传priceType应该怎么做好点呢

goToMotorcycle() {
 this.$router.push({
 path: 'hot-motorcycle',
 query: {
     priceType: this.priceType,
     brandId: this.brandId,
     select: true,
 } })},
阅读 1.5k
1 个回答
goToMotorcycle() {
 let queryData = {
     priceType: this.priceType,
     brandId: this.brandId,
     select: true,
 }
 Object.keys(queryData).map(key => { if(!queryData[key]) delete queryData[key] })
 this.$router.push({
 path: 'hot-motorcycle',
 query: queryData
})},
推荐问题