I created a function in a file getAllUrlParams.js :
function getAllUrlParams(url) {
// get query string from url (optional) or window
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
// we'll store the parameters here
var obj = {};
// if query string exists
if (queryString) {
...
I woulf like to use that function in my vue file :
<script>
import taskDetails from "./taskDetails";
import companyDetails from "../companies/companyDetails";
import addTask from "./addTask";
import editTask from "./editTask";
export default {
name: "tasks",
components: {
You can create a folder and name it "helpers" or "utils", put your folder in resources/js/
Create your function and export:
const getAllUrlParams = () => { //your function body }
export default getAllUrlParams;
Import your function in your component or view:
<script>
import taskDetails from "./taskDetails";
import companyDetails from "../companies/companyDetails";
import addTask from "./addTask";
import editTask from "./editTask";
import getAllUrlParams from "./helpers/getAllUrlParams";
In your getAllUrlParams.js file, put export default before the function keyword.
Like this:
export default function getAllUrlParams(url) {
... // code here
}
Then you can import it easily in your Vue script:
<script>
import taskDetails from "./taskDetails";
import companyDetails from "../companies/companyDetails";
import addTask from "./addTask";
import editTask from "./editTask";
import getAllUrlParams from "./getAllUrlParams";
...
As for where is best to store the file, it's really up to you. Ideally you would keep all common functions in a separate folder to keep things organised.