• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tiny, SSR-safe directive for binding random data to an element.

1️⃣ vue-bind-once

A tiny, SSR-safe directive for binding random data to an element.

A tiny, SSR-safe directive for binding random data to an element.

Quick Start

First install vue-bind-once:

yarn add vue-bind-once

# or npm

npm install vue-bind-once --save

Register directive

import { createApp } from 'vue'
import App from './App.vue'
import { BindOnceDirective, BindOncePlugin } from 'vue-bind-once'

const app = createApp(App)
app.use(BindOncePlugin)
// or app.directive('bind-once', BindOnceDirective)

In most cases you'll be using this directive with an SSR-rendering framework like nuxt, which may have a different way for you to register this directive. For example, in a Nuxt plugin:

import { BindOncePlugin } from 'vue-bind-once'

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.use(BindOncePlugin)
})

Usage

You can now use the directive on any element where you need a binding to a value that needs to match between client/server but won't change dynamically afterwards.

<script setup>
  import { nanoid } from 'nanoid'
  const id = nanoid()
</script>
<template>
  <input type="text" v-bind-once="{ id, name: id }" />
  <label v-bind-once="{ for: id }" />
</template>

This will work on both server and on client re-hydration.

Contributors

This has been developed to suit my needs but additional use cases and contributions are very welcome.

License

MIT License - Copyright Β© Daniel Roe

More Repositories

1

nuxt-vitest

An vitest environment with support for testing code that needs a Nuxt runtime environment
TypeScript
370
star
2

typed-vuex

🏦 A typed store accessor for vanilla Vuex.
TypeScript
346
star
3

page-speed.dev

Vue
330
star
4

nuxt-zero-js

Remove all client-side JS from your Nuxt 3 app
TypeScript
191
star
5

unplugin-purge-polyfills

A tiny plugin to replace package imports with better native code.
TypeScript
190
star
6

nuxt-workers

SSR-safe, zero-config Web Workers integration for Nuxt.
TypeScript
186
star
7

sanity-typed-queries

A typed, zero-dependency schema generator and query builder for Sanity.
TypeScript
173
star
8

nuxt-time

⏰ SSR-safe time element for Nuxt 3
TypeScript
159
star
9

siroc

Zero-config build tooling for Node
TypeScript
149
star
10

nuxt-full-static

Full static implementation for Nuxt 3
TypeScript
117
star
11

roe.dev

This is the code and content for my personal website, built in Nuxt.
TypeScript
113
star
12

n3rdle

Vue
90
star
13

goff

Sync GitHub issues offline into a local folder
TypeScript
70
star
14

rollup-plugin-pure

Annotate functions as pure for Rollup
TypeScript
64
star
15

nuxt-capo

`capo.js` implementation for Nuxt 3
TypeScript
59
star
16

vue-sanity

Sanity integration for Vue Composition API
TypeScript
55
star
17

nuxt-vercel-isr

A tiny demo to show off Nuxt's route rules integration with Vercel.
Vue
55
star
18

nuxt-web-bundle

Generate web bundles with Nuxt
TypeScript
51
star
19

nuxt-pre-hydrate

TypeScript
46
star
20

spooon

This is a tiny recipe app built in Nuxt for a live-coding session at Vue.js Nation 2024.
Vue
33
star
21

nuxt-timings-module

TypeScript
32
star
22

n3dium

This is a tiny, incomplete example for a paywalled content site built in Nuxt 3 for a live-coding session at Vue.js Global Summit 2022.
Vue
30
star
23

trellis-valet-driver

A driver for Laravel Valet that supports the default Trellis install.
PHP
26
star
24

postcss-capsize

TypeScript
25
star
25

agent-conf-2023

A demo of integrating React, Vite and Nitro for AgentConf 2023.
JavaScript
25
star
26

nuxt-vue3-module

TypeScript
22
star
27

nuxt-vscode-template

TypeScript
20
star
28

nuxt-deno

TypeScript
18
star
29

stream-vue

Vue component for Cloudflare Stream.
TypeScript
16
star
30

jetbrains-2023

Vue
15
star
31

firstcommit.is

TypeScript
14
star
32

nuxt-hanko

TypeScript
12
star
33

beasties

A library to inline your app's critical CSS and lazy-load the rest.
JavaScript
11
star
34

frontend-nation-2024

Tiny Nuxt multiplayer app built for a live-coding session at Frontend Nation 2024.
TypeScript
11
star
35

iodigital-2024

Vue
11
star
36

vuejslive

A demo of integrating Vue, Vite and Nitro for Vue.js Live London 2023.
JavaScript
10
star
37

domain-sync

A tiny script that migrates all my Gandi domains to use Cloudflare DNS.
TypeScript
10
star
38

nuxt-turnstile

Cloudflare Turnstile integration for Nuxt
TypeScript
9
star
39

template

JavaScript
9
star
40

future-of-coding-2024

Vue
9
star
41

vuejs-de

TypeScript
7
star
42

unmeta

Simple tools for interacting with HTML metadata tags
TypeScript
7
star
43

vercel-kv

TypeScript
7
star
44

botornot

Vue
7
star
45

nuxt-emoji-blast

TypeScript
6
star
46

renovate

5
star
47

native-esm

JavaScript
4
star
48

nuxt-typed-vuex-example

Vue
4
star
49

vuejs-athens-2024

Vue
4
star
50

flowers

Vue
4
star
51

_productivity_app

Bicep
4
star
52

nuxt-ui-vue

Vue
3
star
53

wearedevs

JavaScript
3
star
54

nuxt3-typed-routes

Vue
3
star
55

pigeon

Vue
3
star
56

danielroe

3
star
57

nuxt-nightly-action

TypeScript
3
star
58

gdg-portlaoise-2024

Vue
3
star
59

vue-subpath-conditions

TypeScript
3
star
60

nuxt-font-metrics

Font metric overrides to reduce CLS
TypeScript
2
star
61

nuxt-demo

TypeScript
2
star
62

partytown-example

TypeScript
2
star
63

viteconf

TypeScript
2
star
64

nuxt3-repros

TypeScript
2
star
65

vue3-pre-window-repro

JavaScript
2
star
66

digital-labin

JavaScript
2
star
67

nuxt-typed-vuex-vue-example

Vue
2
star
68

netlify-dynamic-builder

TypeScript
2
star
69

nuxt-rspack-starter

TypeScript
2
star
70

openflights-loader

TypeScript
1
star
71

building-better-with-nuxt-3

TypeScript
1
star
72

vuejs-berlin

Vue
1
star
73

.github

1
star
74

nuxt-fonts-demo

TypeScript
1
star
75

building-a-pwa-with-nuxt

JavaScript
1
star
76

sanity-module

1
star
77

critters-test

Vue
1
star
78

nuxi-upgrade-yarn3

TypeScript
1
star
79

nuxt-edge-preset

Vue
1
star
80

formkit-init

TypeScript
1
star
81

axios-types

Vue
1
star
82

nuxt-typed-vuex-ts-example

Vue
1
star
83

css-flash-repro

Vue
1
star