For Example I have this
JavaScript
x
7
1
mounted () {
2
this.$router.push({
3
path: '/activatewithphone',
4
query: { serial: this.$route.params.serial, machine: this.$route.params.machine }
5
})
6
},
7
This means whenever a user visits a URL like this
JavaScript
1
2
1
http://example.com/activate?serial=sddsdsds&machine=sdsdsd
2
The user will not be shown a 404 page.
The value of serial and machine is dynamic and can be anything.
My question is there a way to take the values and store its data on mounted
e.g
JavaScript
1
7
1
data: () => {
2
return {
3
serial: '',
4
email: '',
5
}
6
},
7
Can I take the value and assign it to a my serial and email variables, maybe using this.serial
Advertisement
Answer
You could use computed property
:
JavaScript
1
10
10
1
computed: {
2
serial() {
3
return this.$route.query.serial
4
},
5
email() {
6
return this.$route.query.email
7
}
8
9
}
10