Created
July 12, 2017 21:23
-
-
Save nickmessing/f4e8248abeb75223f3a44de75ccd1efe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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