Most used vue composables which I would like to make it betters to share between my projects
This project requires NodeJS (version 16 or later) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.
$ npm -v && node -v
9.6.5
v16.14.0
- @bachdx/b-vuse
BEFORE YOU INSTALL: please read the prerequisites
Start with cloning this repo on your local machine:
To install and set up the library, run:
$ npm i @bachdx/b-vuse
Or if you prefer using Yarn:
$ yarn add @bachdx/b-vuse
The breadcrumb control that can share across all components without using localStorage or any storage but still
reactive
Most of my project using the same structure for breadcrumb as below
const breadcrumb = {
title: "Dummy title",
items: [
{
text: "First Item",
href: "/first-item",
active: false, // should be false for all items except last one
},
{
text: "Last Item",
href: "/last-item",
active: true,
},
// ...another last on your demands
],
};
And the component
for rendering the breadcrumb
<template>
<div class="row">
<div class="col-12">
<div
class="page-title-box d-flex align-items-center justify-content-between"
>
<h4 class="mb-0 font-size-18">{{ breadcrumb.title }}</h4>
<div class="page-title-right">
<!-- I use vue bootrap here but you can you anything you want -->
<b-breadcrumb class="m-0">
<b-breadcrumb-item
v-for="(item, i) in breadcrumb.items"
:key="i"
:text="item.text"
:to="item.href"
:active="item.active"
></b-breadcrumb-item>
</b-breadcrumb>
</div>
</div>
</div>
</div>
</template>
So if you dont want to use the title, be my guest, just remove the breadcrumb.title
import { useBreadcrumb } from "@bachdx/b-vuse";
import { useBreadcrumb } from "@bachdx/b-vuse";
const { setBreadcrumb } = useBreadcrumb();
setBreadcrumb({
title: "User List",
items: [
{
text: "User",
href: "/users",
},
{
text: "List",
active: true,
},
],
});
import { useBreadcrumb } from "@bachdx/b-vuse";
const { breadcrumb, getBreadcrumb } = useBreadcrumb();
getBreadcrumb();
after this you should be able to change the page
( components ) and will have the reactive
breadcrumb on every page
You might need to set your router
setup to reset
the content of breadcrumb
before each route changed by doing this
setBreadcrumb({});
Type | Name | Attributes/Params |
---|---|---|
ref | breadcrumb | { 'title': String, 'items': [{'text: String, 'href': String, 'active': Boolean }] } |
function | getBreadcrumb | None |
function | setBreadcrumb | { 'title': String, 'items': [{'text: String, 'href': String, 'active': Boolean }] } |
The query object that most of my project use for supporting query data from server and paging support
const queryInput = {
page: 1,
perPage: 10,
q: {}, // this should be ransacker support object
};
import { useQuery } from "@bachdx/b-vuse";
const { queryInput, resetQuery, updateQuery } = useQuery();
or you can change the default params as your needs
const { queryInput, resetQuery, updateQuery } = useQuery({ perPage: 15 });
updateQuery({ page: page });
Type | Name | Attributes/Params |
---|---|---|
QueryInput | queryInput | { 'page': 1, 'perPage': 10, 'q': {} } |
function | resetQuery | None |
function | updateQuery | { 'page': 1, 'perPage': 10, 'q': {} } |
The query object that most of my project use for supporting query data from server and paging support
import { useGoQuery } from "@bachdx/b-vuse";
const query = reactive({}); // this could be anything related to search key
const { goQueryInput, updatePage } = useGoQuery({ perPage: 10, query: query });
updatePage(page, callbackFunction);
Type | Name | Attributes/Params |
---|---|---|
GoQueryInput | goQueryInput | { pagyInput: {'page': , 'perPage': }, 'query': {} } |
function | updatePerPage | perPage |
function | updatePage | page, callbackFunction |
function | updateQuery | { 'page': 1, 'perPage': 10, 'q': {} } |
function | resetQuery | callbackFunction |
- Clone it!
- Create your feature branch:
git checkout -b my-new-feature
- Add your changes:
git add .
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 😎
- bachdx (https://github.com/bachdx2812)
- Hopefully more to come here...
UNLICENSED