https://github.com/ZeroDark1991/vue-update
provides extra hook for data-updating
https://github.com/ZeroDark1991/vue-update
Last synced: 3 days ago
JSON representation
provides extra hook for data-updating
- Host: GitHub
- URL: https://github.com/ZeroDark1991/vue-update
- Owner: ZeroDark1991
- Created: 2016-11-28T09:13:37.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-12-25T05:31:38.000Z (almost 9 years ago)
- Last Synced: 2025-10-10T02:39:54.387Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 54.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-vue-refactor - vue-update
README
# vue-update [](https://www.npmjs.com/package/vue-update)
> Requires Vuejs 2.0
> Must works with [vue-router](https://github.com/vuejs/vue-router)
You can use it to manually control whether data should be updated when route enters, or do some things else.
It can be helpful in some cases, especially in 'keep-alive' mode.
## Install
```
$ npm install vue-update --save-dev
```
main.js:
```js
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueUpdate from 'vue-update'
Vue.use(VueRouter)
Vue.use(VueUpdate)
```
## usage
see /example
```
$ npm install
$ npm run dev
```
Use ``` this.$pushToUpdate('/foo') ``` to push a route path into the updateQueue.
In bar.vue:
```js
// push the route which needs to update
this.$pushToUpdate('/foo')
// you can also pass the route name
this.$pushToUpdate('foo')
```
Then when you navigate to a route the matches anyone in the updateQueue, the hook function ``` update(){} ``` in the target route will trigger.
In foo.vue:
```js
export default {
data(){
return {
msg: ''
}
},
update(){
// do something
this.msg = 'foo'
// once triggerd, '/foo' will be removed from the list
}
}
```