P粉3221067552023-08-26 10:17:11
Route parameters can contain many values with the same key. That's why it's probably an array of strings and not a single string. If you are sure there is only one parameter, you can use as string
to tell the typescript compiler that you know 100% that this variable is a string
and not a <代码>string[]代码>
this.resetPassword(password1.value, password2.value, this.$route.params.id as string, this.$route.params.resetID as string)
If you would use .toString()
and would have an array like ["foo", "bar"]
you would get "foo , bar"
as the result of .toString()
If you are not sure whether it is an array, you can check it. If it is an array, take the first value:
let id: string; if (Array.isArray(this.$route.params.id)) { id = this.$route.params.id[0]; } else { id = this.$route.params.id; }