1.1.35 • Published 4 months ago

vue-json-debug v1.1.35

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Vue-json-debug

STAGE: RFC

preview.png

A simple Vue component to display JSON data in multiple components.

  • Reactive Preview
  • Show/Hide Debug Components
  • Dev only (not included in production builds)

Installation

npm install vue-json-debug
# OR
yarn add vue-json-debug

Usage

import {createApp} from 'vue';
import App from './App.vue';

// Import plugin
import {useDebugPlugin} from 'vue-json-debug/src/plugin';
// Import plugin styles
import 'vue-json-debug/src/debug.css';

const app = createApp(App);

useDebugPlugin(app, {
    // Register the `<debug>` component globally
    registerDebugComponent: true,
});

app.mount('#app');

Add DebugDock to your app

In order to have the debug dock show up, you need to add the <debug-dock> component to your app.

It should be placed in your root component, or in a component that is always visible.

<template>
    ... your app template
    <debug-dock/>
</template>

Debug Component

The <debug> component is used to display the JSON data. It can be used anywhere in your app.

<script setup lang="ts">
import {ref} from "vue";

const form = ref({foo: 'bar'});
</script>

<template>
  <debug :data="{form}"/>
</template>

Options

type DebugPluginOptions = {
    enableIf: () => boolean;
    dock: {
        hideIfNoSlots?: boolean;
        slotTitleLimit?: number;
    };
    defaultDebugTheme: string;
    registerDebugComponent: boolean;
    components?: {
        before?: Record<string, Component>;
        after?: Record<string, Component>;
    };
};
OptionTypeDefaultDescription
enableIf() => boolean() => trueA function that returns a boolean to enable/disable the plugin.
dockObjectAn object that contains the dock options.
dock.hideIfNoSlotsbooleanfalseIf true the dock will be hidden if there are no slots to display. If you want the dock to be always visible, set this option to false.
dock.slotTitleLimitnumber20The maximum number of characters to display in the slot title before truncating it.
defaultDebugThemestringdarkThe default theme to use for the debug component. You can use the following values: light, dark.
registerDebugComponentbooleanfalseIf true the <debug> component will be registered globally.
componentsObjectAn object that contains the components to register globally. This provides a way to add more components to the debug component.
components.beforeObjectAn object that contains the components to register before the default components.
components.afterObjectAn object that contains the components to register after the default components.

Debug Component Props

type DebugProps = {
    data: object;
    forceShow?: boolean;
    space?: number;
    name?: string;
    hideName?: boolean;
    hideFirst: boolean;
    theme?: string;
    useParentName?: boolean;
};
PropTypeDefaultDescription
dataobjectThe data to display.
forceShowbooleanfalseIf true the debug component will be shown no matter what.
spacenumber2The number of spaces to use for JSON indentation.
namestringThe name to display.
hideNamebooleanfalseIf true the name will be hidden.
hideFirstbooleanfalseIf true it will be hidden before mount.
themestringThe theme to use for the debug component.
useParentNamebooleanfalseIf true the name of the parent file where the debug component is called from will be used as name

Available Dock Components

  • RouteInfo - Displays the current route name. (Requires vue-router)
  • ScreenSize - Displays the current screen width and height. (Requires @vueuse/core)

Registering Components

The Docker supports registering components before and after the default components. This provides a way to add more components to the debug component.

import RouterInfo from "vue-json-debug/src/docks/RouterInfo.vue";
import ScreenSize from "vue-json-debug/src/docks/ScreenSize.vue";

useDebugPlugin(app, {
    components: {
        after: {RouterInfo, ScreenSize},
    },
});

Nuxt 3 Implementation

To add this package to nuxt, you need to create a plugin. A nuxt plugin gives you the vue app instance.

export default defineNuxtPlugin((nuxtApp) => {
    const app = nuxtApp.vueApp;
    
    useDebugPlugin(app, {
        registerDebugComponent: true,
    });
});

Add the plugin and styles to your nuxt.config.ts file.

export default defineNuxtConfig({
    css: [
        // ... your other styles
        'vue-json-debug/src/debug.css'
    ],
    plugins: [
        // ... your other plugins
        {
            src: '@/plugins/path/to/your/plugin.ts',
            mode: 'client'
        }
    ],
});

Add DebugDock to your app just like in the Vue example. But surrounded by a <client-only> component.

<template>
  <client-only>
    <debug-dock/>
  </client-only>
</template>
1.1.35

4 months ago

1.1.30

6 months ago

1.1.34

6 months ago

1.1.33

6 months ago

1.1.32

6 months ago

1.1.31

6 months ago

1.1.29

9 months ago

1.1.28

11 months ago

1.1.12

11 months ago

1.1.16

11 months ago

1.1.15

11 months ago

1.1.14

11 months ago

1.1.13

11 months ago

1.1.19

11 months ago

1.1.18

11 months ago

1.1.17

11 months ago

1.1.23

11 months ago

1.1.22

11 months ago

1.1.21

11 months ago

1.1.20

11 months ago

1.1.27

11 months ago

1.1.26

11 months ago

1.1.25

11 months ago

1.1.24

11 months ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago