All Projects → jeffreyguenther → Vue Turbolinks

jeffreyguenther / Vue Turbolinks

Licence: mit
A Vue mixin to fix Turbolinks caching

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Turbolinks

Super module
SuperModule allows defining class methods and method invocations the same way a super class does without using def included(base). This also succeeds ActiveSupport::Concern by offering lighter syntax
Stars: ✭ 133 (-51.1%)
Mutual labels:  rails, mixins
Vueonrails
💎 Rails gem with the power of Vue.js components
Stars: ✭ 250 (-8.09%)
Mutual labels:  rails, vue-components
Second level cache
Write Through and Read Through caching library inspired by CacheMoney and cache_fu, support ActiveRecord 4, 5 and 6.
Stars: ✭ 380 (+39.71%)
Mutual labels:  cache, rails
Rails kindeditor
Kindeditor for Ruby on Rails
Stars: ✭ 263 (-3.31%)
Mutual labels:  rails
Role core
🔐A Rails engine providing essential industry of Role-based access control.
Stars: ✭ 262 (-3.68%)
Mutual labels:  rails
Imagvue
🎑 Imagvue is an image component for Vue.js
Stars: ✭ 268 (-1.47%)
Mutual labels:  vue-components
Gcache
gcache是gorm的中间件,插入后gorm即刻拥有缓存。
Stars: ✭ 271 (-0.37%)
Mutual labels:  cache
Vue Patterns
Useful Vue patterns, techniques, tips and tricks and helpful curated links.
Stars: ✭ 2,898 (+965.44%)
Mutual labels:  vue-components
Nutui
京东风格的移动端 Vue2、Vue3 组件库 (A Vue.js UI Toolkit for Mobile Web)
Stars: ✭ 3,870 (+1322.79%)
Mutual labels:  vue-components
Form Create
🔥🔥🔥 强大的动态表单生成器|form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON.
Stars: ✭ 3,698 (+1259.56%)
Mutual labels:  vue-components
Ristretto
A high performance memory-bound Go cache
Stars: ✭ 3,584 (+1217.65%)
Mutual labels:  cache
Php Simplecache
A simple script for caching 3rd party API calls in PHP
Stars: ✭ 264 (-2.94%)
Mutual labels:  cache
Thinreports Generator
Report Generator for Ruby
Stars: ✭ 268 (-1.47%)
Mutual labels:  rails
Arclight
A Bukkit(1.15/1.16) server implementation on Forge using Mixin. ⚡
Stars: ✭ 262 (-3.68%)
Mutual labels:  mixins
Creek
Ruby library for parsing large Excel files.
Stars: ✭ 270 (-0.74%)
Mutual labels:  rails
Portus
Authorization service and frontend for Docker registry (v2)
Stars: ✭ 2,880 (+958.82%)
Mutual labels:  rails
Elasticsearch Rails
Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
Stars: ✭ 2,896 (+964.71%)
Mutual labels:  rails
Doctrinecachebundle
Symfony2 Bundle for Doctrine Cache
Stars: ✭ 2,813 (+934.19%)
Mutual labels:  cache
Material icons
A simple Rails wrapper for Google Material Icons
Stars: ✭ 266 (-2.21%)
Mutual labels:  rails
Kinto.js
An Offline-First JavaScript Client for Kinto.
Stars: ✭ 268 (-1.47%)
Mutual labels:  cache

A Turbolinks & Hotwire Adapter for Vue components

npm vue-turbolinks package version npm vue-turbolinks package downloads npm vue-turbolinks license

vue-turbolinks is a package to allow you to easily add Vue.js components to your Turbolinks & Hotwire powered apps. We handle the events to properly setup and teardown your Vue components on the page.

Supported Libraries

⚠️ If you're using vue-router or another Javascript routing library, you don't need to use Turbolinks or this adapter. Turbolinks is meant to level up the traditional request-render cycle by loading the new page in the background and this adapter makes it possible to use Vue components on pages rendered in this manner. If you've decided to use a single-page app, you already have everything you need. 🤘

To use this in a Rails project with webpacker support:

$ ./bin/yarn add vue-turbolinks

To use the mixin, include it where you setup your component. For example, if you used rails new myapp --webpack=vue to create your project using webpacker, you'll include it in your hello_vue.js file:

Mixin Option 1: Global

import TurbolinksAdapter from 'vue-turbolinks';
Vue.use(TurbolinksAdapter);

document.addEventListener('turbo:load', () => {
  const vueapp = new Vue({
    el: "#hello",
    template: '<App/>',
    components: { App }
  });
});

Mixin Option 2: Single Component

import { turbolinksAdapterMixin } from 'vue-turbolinks';

document.addEventListener('turbo:load', () => {
  const vueapp = new Vue({
    el: "#hello",
    template: '<App/>',
    mixins: [turbolinksAdapterMixin],
    components: { App }
  });
});

Running Vue only on specific pages

If you want your Vue component to run only on certain pages, you can conditionally initialize it:

import TurbolinksAdapter from 'vue-turbolinks';
Vue.use(TurbolinksAdapter);

document.addEventListener('turbo:load', () => {
  const element = document.getElementById("hello");

  if (element != null) {
    const vueapp = new Vue({
      el: element,
      template: '<App/>',
      components: { App }
    });
  }
});

Or you can use a library like Punchbox whose JS is available for the asset pipeline or on NPM.

Options

You can pass in destroyEvent if you would like to customize which event Vue is torn down on. By default, this uses turbo:before-cache or turbolinks:before-cache.

Vue.use(TurbolinksAdapter, { destroyEvent: 'turbo:before-cache' });

A note on transitions

If a $root component's root node is a Vue <transition> then calling the $destroy method may fail, throwing NoModificationAllowedError: Failed to set the 'outerHTML' property on 'Element' errors on the next turbo:visit event. To prevent this, wrap the transition in a DOM element:

Instead of:

<template>
  <transition name="my-transition">
    <div v-if="ui_state.show" class="modal">
...

do:

<template>
  <div>
    <transition name="my-transition">
      <div v-if="ui_state.show" class="modal">
...
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].