- 傳遞的引數為params物件
export default {
data () {
return {
phone: '18688754577',
password: '123456'
}
},
computed: {
params () {
let params = {}
params.phone = this.phone
params.password = this.password
return params
}
},
methods: {
concatParams (params) {
let paramsStr = ''
for (var k in params) {
paramsStr += k + '=' + params[k] + '&'
}
paramsStr = '?'+ paramsStr.substr(0, paramsStr.length - 1)
return paramsStr
}
},
created () {
concatParams (this.params)
}
}
複製程式碼
- 物件的遍歷
for (var k in params) {
/* k => 指代的是key*/
/* params[k] => 指代的是value */
}
複製程式碼