@bachdx/b-vuse
v1.6.1
Published
useful self made vue3 composables
Downloads
322
Readme
@bachdx/b-vuse
Most used vue composables which I would like to make it betters to share between my projects
Prerequisites
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
Table of contents
- @bachdx/b-vuse
Getting Started
Installation
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
Core Functions
useBreadcrumb
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
import { useBreadcrumb } from "@bachdx/b-vuse";
Usage Example:
In page
(component) where you need to change the breadcrumb
import { useBreadcrumb } from "@bachdx/b-vuse";
const { setBreadcrumb } = useBreadcrumb();
setBreadcrumb({
title: "User List",
items: [
{
text: "User",
href: "/users",
},
{
text: "List",
active: true,
},
],
});
In the actual breadcrumb
rendering component
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
Notice:
You might need to set your router
setup to reset
the content of breadcrumb
before each route changed by doing this
setBreadcrumb({});
Data and Methods
| 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 }] } |
useQuery ( use for Rails backend and pagy + ransack supported )
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
import { useQuery } from "@bachdx/b-vuse";
Usage Example:
In Pinia Store and components ( maybe )
const { queryInput, resetQuery, updateQuery } = useQuery();
or you can change the default params as your needs
const { queryInput, resetQuery, updateQuery } = useQuery({ perPage: 15 });
To update query ( such as page)
updateQuery({ page: page });
Data and Methods
| Type | Name | Attributes/Params | | ---------- | ----------- | ------------------------------------- | | QueryInput | queryInput | { 'page': 1, 'perPage': 10, 'q': {} } | | function | resetQuery | None | | function | updateQuery | { 'page': 1, 'perPage': 10, 'q': {} } |
useGoQuery ( use for Go backend )
The query object that most of my project use for supporting query data from server and paging support
Import
import { useGoQuery } from "@bachdx/b-vuse";
Usage Example:
In Pinia Store and components ( maybe )
const query = reactive({}); // this could be anything related to search key
const { goQueryInput, updatePage } = useGoQuery({ perPage: 10, query: query });
To update page/perPage/Query
updatePage(page, callbackFunction);
Data and Methods
| 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 |
Contributing
- 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 :sunglasses:
Authors
- bachdx (https://github.com/bachdx2812)
- Hopefully more to come here...
License
UNLICENSED