To use a named API route with parameters inside a Vue component, you can use the route() method provided by Laravel. You can pass the route name and any required parameters as arguments to the method. Here's an example:
import { route } from 'laravel-mix';
export default {
data() {
return {
projects: [],
categoryId: 1,
page: 2,
includeCategory: true,
};
},
mounted() {
this.fetchProjects();
},
methods: {
fetchProjects() {
const url = route('api.v1.projects', {
categoryId: { eq: this.categoryId },
page: this.page,
includeCategory: this.includeCategory,
});
axios.get(url).then(response => {
this.projects = response.data;
});
},
},
};
In this example, we're using the route() method to generate the URL for the api.v1.projects route, passing in the required parameters as an object. We're then using Axios to make a GET request to the generated URL and update the component's projects data property with the response data.