Skip to content

Instantly share code, notes, and snippets.

View yyx990803's full-sized avatar

Evan You yyx990803

View GitHub Profile
@yyx990803
yyx990803 / data.js
Last active November 2, 2015 20:17
var object = {
message: 'Hello world!'
}
<div id=”example”>
{{ message }}
</div>
new Vue({
el: ‘#example’,
data: object
})
var example = new Vue({
data: {
a: 1
},
computed: {
b: function () {
return this.a + 1
}
}
})
var Example = Vue.extend({
template: '<div>{{ message }}</div>',
data: function () {
return {
message: 'Hello Vue.js!'
}
}
})
// register it with the tag <example>
<!-- MyComponent.vue -->
<!-- css -->
<style>
.message {
color: red;
}
</style>
<!-- template -->
import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './app.vue'
import ViewA from './view-a.vue'
import ViewB from './view-b.vue'
Vue.use(VueRouter)
const router = new VueRouter()
export default {
render () {
return <App><Text></Text></App>
}
}
// fesfesf
// fesfsef
// App.js
// using .jsx extension because gist syntax
// highlighting chokes on `export default`
import ComponentA from './ComponentA'
export default {
// use another component, in this scope only.
// ComponentA maps to the tag <component-a>
components: { ComponentA },
template: `
@yyx990803
yyx990803 / workerify.js
Last active December 17, 2015 08:09
Turn a function's body into a worker.
// Turns a function's body into a worker
var workerify = function (func) {
if (typeof func !== 'function') {
throw new Error('expects a function to workerify.')
}
var script = func.toString().match(/^function[^{]*{((.|\n)*)}$/)[1],
blob = new Blob([script], {'type': 'application/javascript'}),
url = window.URL.createObjectURL(blob)
return new Worker(url)
}