export default {
name: 'AuthCallback',
data() {
return {
accessToken: null,
}
},
mounted() {
const tokenParseRegex: RegExp = /access_token=(.*?)&/;
const idParseRegex: RegExp = /user_id(.*?)/;
const exAccessToken: RegExpMatchArray | null = useRoute().hash.match(tokenParseRegex);
this.data().accessToken = exAccessToken![1];
}
}
this.data().accessToken = exAccessToken![1] - Whats wrong with this line? Error is The type "string" cannot be assigned to the type "null". and in console this.data is not a function
CodePudding user response:
Try to use
this.accessToken = exAccessToken![1]
Instead of
this.data().accessToken = exAccessToken![1]
The error comes up because you are writing "data()" after "this", so it's being interpreted as a function.
While acessing data, you can simply use
this.nameOfVar
CodePudding user response:
You can give a try by expanding your data
object by assigning a type to it.
data() : { accessToken: null | string }
{
return {
accessToken: null,
}
}