Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
vue-turbolinks
Advanced tools
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.
:warning: 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. :metal:
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:
import TurbolinksAdapter from 'vue-turbolinks';
Vue.use(TurbolinksAdapter);
document.addEventListener('turbo:load', () => {
const vueapp = new Vue({
el: "#hello",
template: '<App/>',
components: { App }
});
});
import { turbolinksAdapterMixin } from 'vue-turbolinks';
document.addEventListener('turbo:load', () => {
const vueapp = new Vue({
el: "#hello",
template: '<App/>',
mixins: [turbolinksAdapterMixin],
components: { App }
});
});
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.
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' });
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">
...
FAQs
A Vue mixin to make components work with Turbolinks' cache
We found that vue-turbolinks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.