I have a component.
<template> <HotTable :settings="hotSettings" ></HotTable> </template> <script> import HotTable from "@handsontable/vue"; import Handsontable from "handsontable"; export default { data() { return { hotSettings: { data: [ ["", "Ford", "Volvo", "Toyota", "Honda"], ["2016", "10", 11, 12, 13], ["2017", 20, 11, 14, 13], ["2018", 30, 15, 12, 13] ], rowHeaders: true, colHeaders: true } }; }, components: { HotTable } }; </script> This component is displayed in three different paths: /path/path1 , /path/path2 , /path/path3 . How can I make it so that, following these paths, this component is displayed on each page, but the data for it (the data field) is different?
Recently prompted to use props in routes. It turned out the following.
Component
<template> <HotTable :data="myData"></HotTable> </template> <script> import HotTable from "@handsontable/vue"; import Handsontable from "handsontable"; export default { data: function() { return {} }; }, props: ["myData"], components: { HotTable } }; </script> <style src="handsontable/dist/handsontable.full.css"></style> <style> #hot-preview { width: 600px; height: 400px; overflow: hidden; } </style> File with routes
export default new Router({ routes: [{ path: '/tables/groups', component: Table, props: { myData: [ ["", "Ford", "Volvo", "Toyota", "Honda"], ["2016", 10, 11, 12, 13], ["2017", 20, 11, 14, 14], ["2018", 30, 15, 12, 15] ] }, }, { path: '/tables/subjects', component: Table, props: { myData: [ ["", "Ford", "Volvo", "Toyota", "Honda"], ["2016", 10, 11, 12, 15], ["2017", 20, 11, 14, 14], ["2018", 30, 15, 12, 13] ] }, }, ], }) This solution is working, but I need to dynamically retrieve data for the table, so I use the storage. How can I associate a repository with this design?
File store.js
export const store = new Vuex.Store({ state: { groupsTableData: [], }, actions: { loadGroupsTableData({commit}) { axios .get("/api/tables/groups") .then((response) => { commit("SET_GROUPS_TABLE_DATA", response.data); console.log(response); }) .catch((error) => { console.log(error); }); }, }, mutations: { SET_GROUPS_TABLE_DATA(state, data) { state.groupsTableData = data; }, }, getters: { groupsTableData: state => { return state.groupsTableData } } })