# statefulvue

> A directive of vue to save page state

Latest version **1.0.1** (published 2021-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install statefulvue
pnpm add statefulvue
yarn add statefulvue
bun add statefulvue
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-08-25 |
| First published | 2021-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | xt |
| Maintainers | xt_chn |
| Keywords | vue, directive |

## Links

- npm: https://www.npmjs.com/package/statefulvue
- Repository: https://github.com/xtzero/statefulvue
- Homepage: http://xtzero.me?from=npm_stateful
- Issues: https://github.com/xtzero/statefulvue/issues
- npm.io page: https://npm.io/package/statefulvue

## Dependencies (2)

- [vue](https://npm.io/package/vue.md) ^2.6.14
- [vuex](https://npm.io/package/vuex.md) ^3.6.2

## Recent versions

- 1.0.1 (latest) — 2021-08-25
- 1.0.0 — 2021-08-25

## README

# statefulvue

> 保存状态的自定义指令
>
> xt
>
> [官网地址](http://xtzero.me/_posts/stateful202108/index.html)

在任意需要保存状态的组件上使用 v-stateful，即可在当前Vue生命周期内，路由切换的过程中保留其绑定的值。例如：

```html
<el-input v-model="value" v-stateful></el-input>
```

可以对组件提供 :query-key="queryKey" 属性，来优先从queryKey的url参数里获取值。例如：

```html
<el-input v-model="value" query-key="input_value" v-stateful></el-input>
```

对于一些不是使用v-model绑定的组件，需要为其指定 state-key，来让stateful指令知道需要绑定到data下的哪个值
这些组件往往不是双向绑定，所以需要将key绑定到 $store.getters.randNum 上，来保证每次都会更新组件状态。例如：

```html
<pagination v-stateful state-key="page.page" :page.sync="page.page" :key="$store.getters.randNum" />
```

如果一个组件使用了v-stateful，但没有v-model和state-key，则会报错：使用v-stateful，v-model 和 :state-key至少有其一。

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