@invoate/alpine-query-string

1.0.0 • Public • Published

Query String Binding for AlpineJS

🚧 👷 ⚠️ This is a work in progress. ⚠️ 👷 🚧

This is a simple plugin for AlpineJS that binds a property to a specified url query parameter.

Installation

You can install this package via NPM:

npm install @invoate/alpine-query-string

or by CDN:

<!-- Plugin -->
<script src="https://unpkg.com/@invoate/alpine-query-string/dist/alpine-query-string.min.js" defer></script>
<!-- AlpineJS -->
<script src="https://unpkg.com/alpinejs/dist/cdn.min.js" defer></script>

Setup

First you must register the plugin with Alpine.

import Alpine from "alpinejs"
import queryString from "@invoate/alpine-query-string"

Alpine.plugin(queryString)

Alpine.start()

Usage

In your views, you can now use the x-query-string directive.

<div x-data="{ selected: 'option' }" x-query-string.param="selected">
  <!-- When `selected` changes ?param=value will be appended to the url -->
  <!-- Visiting this page with ?param=value will set `selected` to `value` -->
</div>

When the first modifier is not set the parameter name will default to the name of the property

<div x-data="{ selected: 'option' }" x-query-string="selected">
  <!-- ?selected=value will be appended to the url -->
</div>

Credits

License

The MIT License (MIT). Please see License File for more information.

Readme

Keywords

none

Package Sidebar

Install

npm i @invoate/alpine-query-string

Weekly Downloads

89

Version

1.0.0

License

MIT

Unpacked Size

8.41 kB

Total Files

11

Last publish

Collaborators

  • olumby