In this part, we will create the <script> section of the single file component. Follow these instructions to create the component correctly:
- Open contact.vue in the src/views folder.
- Add a new mounted property:
mounted() {}
- In this property, we will add a verification that will check whether there are any parameters on the $route.params object and display an alert with that $route.params:
mounted() {
if (Object.keys(this.$route.params).length) {
alert(`Hey! I've got some parameter!
${JSON.stringify(this.$route.params)}`);
}
},
To run the server and see your component, you need to open Terminal (macOS or Linux) or Command Prompt/PowerShell (Windows) and execute the following command:
> npm run serve
Here is your component rendered and running: