# @zlinst/vue2-sandbox

> An interactive Vue component for previewing other Vue component on the fly.

Latest version **0.1.3** (published 2021-04-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zlinst/vue2-sandbox
pnpm add @zlinst/vue2-sandbox
yarn add @zlinst/vue2-sandbox
bun add @zlinst/vue2-sandbox
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2021-04-11 |
| First published | 2021-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Lin |
| Maintainers | zlinst |
| Keywords | vuejs, vue, vue2, component, sandbox, preview |

## Links

- npm: https://www.npmjs.com/package/@zlinst/vue2-sandbox
- Repository: https://github.com/zlinst/vue-sandbox
- Homepage: https://github.com/zlinst/vue-sandbox#readme
- Issues: https://github.com/zlinst/vue-sandbox/issues
- npm.io page: https://npm.io/package/@zlinst/vue2-sandbox

## Recent versions

- 0.1.3 (latest) — 2021-04-11
- 0.1.2 — 2021-04-11
- 0.1.1 — 2021-04-10
- 0.1.0 — 2021-04-09

## README

# vue2-sandbox

**vue2-sandbox** provides a customisable and interactive component for previewing Vue component on the fly which can be useful for testing or demostration.

## This project is still under active development.

## Basic Usage

### Use the `component` prop:

```vue
<template>
  <component-sandbox :component="FooComponent" />
</template>

<script>
import FooComponent from './components/FooComponent.vue'

export default {
  components: {
    FooComponent,
  },
}
</script>
```

Or

### Use the default slot 

Note the manual bindings for `propsData` and `eventsData` are needed in this case.

```vue
<template>
  <component-sandbox>
    <template v-slot="{ propsData, eventsData }">
      <foo-component v-bind="propsData" v-on="eventsData" />
    </template>
  </component-sandbox>
</template>

<script>
// ... omitted
</script>
```

## Advanced Usage

### Custom Prop Input

We can use custom input component for editing prop value by using named slot `prop:{propName}`.

For example, if `UserProfile` component has a prop named `userId`, and `FormUserId` is a selector component that loads users from remote server and emits id of selected user as `v-model`.

```vue
<template>
  <component-sandbox :component="UserProfile">
    <template v-slot:prop:userId="{ prop }">
      <form-user-id v-model="prop.valueProxy" />
    </template>
  <component-sandbox>
</template>

<script>
import UserProfile from './components/UserProfile.vue'
import FormUserId from './components/FormUserId.vue'

export default {
  components: {
    UserProfile,
    FormUserId,
  },
}
</script>
```

### Unlisted Props

Sometimes we use `$attrs` to pass non-prop attributes to child component, we can use `props` prop to include them in the prop list as well, it's just like how we define `props` in Vue component.

```vue
<template>
  <component-sandbox
    :component="FooComponent"
    :props="{
      bar: {
        type: String,
        default: 'Hello, This is BAR',
      }
    }"
  />
</template>

<script>
// ... omitted
</script>
```

Or make it fancier:

```vue
<template>
  <component-sandbox
    :component="FooComponent"
    :props="BarComponent.$props"
  />
</template>

<script>
import BarComponent from './component/BarComponent.vue'

// ... omitted
</script>
```

### Eval Mode

The "edit" button next to the prop name allows us to set the prop value using JSON, we can also use eval mode for data that is not supported by JSON, such as `Function`.

This feature is disabled by default, and requires manual activation for security reasons.

---
_Source: https://npm.io/package/@zlinst/vue2-sandbox · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
