Skip to content

Instantly share code, notes, and snippets.

@nickmessing
Created July 12, 2017 21:23
Show Gist options
  • Save nickmessing/f4e8248abeb75223f3a44de75ccd1efe to your computer and use it in GitHub Desktop.
Save nickmessing/f4e8248abeb75223f3a44de75ccd1efe to your computer and use it in GitHub Desktop.
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-router"></script>
<div id="app">
<h2>{{ count }}</h2>
<button @click="inc">inc</button>
<button @click="dec">dec</button>
</div>
const Foo = { template: '<div>foo</div>' }
const routes = [
{ path: '/foo', component: Foo },
]
const router = new VueRouter({
routes
})
const HTTPRequest = {}
HTTPRequest.install = (Vue, options) => {
let http = null
Object.defineProperty(Vue.prototype, '$request', {
get () {
return {
request: (method, url, data, redirects = true) => {
console.log('request');
},
get: (url, data = null, redirects = true) => {
console.log(this.$router);
},
}
}
})
}
Vue.use(HTTPRequest)
new Vue({
el: '#app',
router,
data: { count: 0 },
methods: {
inc() {
this.count++
this.$request.get()
},
dec() {
this.count--
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment