Karl Kedrovsky
VML
karl.kedrovsky@vml.com
karl@kedrovsky.com
@karlkedrovsky
The goal of Vue.js is to provide the benefits of reactive data binding and composable view components with an API that is as simple as possible.
Message:
Message:
{{ message }}
new Vue({
el: '#app',
data: {
message: ''
}
});
Demo
Count: {{ count }}
new Vue({
el: '#app',
data: {
count: 0
},
methods: {
add: function() {
this.count++;
}
}
});
Demo
var Foo = Vue.extend({
template: 'The Foo Component
'
});
Vue.component('foo', Foo);
var Bar = Vue.extend({
template: 'The Bar Component
'
});
Vue.component('bar', Bar);
new Vue({
el: '#app'
});
Demo
var SpawnOfFoo = Vue.extend({
template: 'The Spawn Of Foo Component
'
});
var Foo = Vue.extend({
template: 'The Foo Component
',
components: {
'spawn-of-foo': SpawnOfFoo
}
});
Vue.component('foo', Foo);
var Bar = Vue.extend({
template: 'The Bar Component
'
});
Vue.component('bar', Bar);
new Vue({
el: '#app'
});
Demo
Demo Component
{{ message }}
import Vue from 'vue';
import Demo from './components/demo.vue';
new Vue({
el: '#app',
components: {
Demo
}
});
gulp.task('webpack', function() {
return gulp.src('js_sfc/sfc.js')
.pipe(webpack({
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel'
},
{
test: /\.vue$/,
loader: 'vue'
}
]
},
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
},
resolve: {
modulesDirectories: ['node_modules']
},
output: {
filename: 'sfc.js'
}
}))
.pipe(gulp.dest('web/js/'));
});
Demo
{# field--field-component-name.html.twig #}
{% for item in items %}
<{{ item.content }}></{{ item.content }}>
{% endfor %}
vue.info.yml
name: Vue.js and Drupal
type: theme
description: Demo theme for Vue.js and Drupal
base theme: bartik
core: 8.x
libraries:
- vue/main
vue.libraries.yml
main:
version: 1.x
js:
js/vue.js: {}
js/main.js: {}
gulpfile.js
gulp.task('webpack', function() {
return gulp.src('src/main.js')
.pipe(webpack({
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel'
},
{
test: /\.vue$/,
loader: 'vue'
}
]
},
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
},
resolve: {
modulesDirectories: ['node_modules']
},
output: {
filename: 'main.js'
}
}))
.pipe(gulp.dest('js/'));
});
src |-- components | |-- app.vue | |-- cat_counter.vue | |-- cats.vue | |-- cat.vue | |-- demo.vue |-- main.js
{{ title }}
{{ message }}
import Vue from 'vue';
import Demo from './components/demo.vue';
new Vue({
el: '#page',
components: {
Demo
}
});
Demo
{{ title }}
{{{ picture }}}
import Vue from 'vue';
import VueResource from 'vue-resource';
Vue.use(VueResource);
import Demo from './components/demo.vue';
import Cat from './components/cat.vue';
new Vue({
el: '#page',
components: {
Demo,
Cat
}
});
import Vue from 'vue';
import VueResource from 'vue-resource';
Vue.use(VueResource);
import Demo from './components/demo.vue';
import Cat from './components/cat.vue';
import Cats from './components/cats.vue';
new Vue({
el: '#page',
components: {
Demo,
Cat,
Cats
},
methods: {
ready() {
this.$on('new-cat', function(cat) {
this.$broadcast('new-cat', cat);
}, (response) => {
console.log('Error');
});
}
}
});
Demo
Cat Pictures Viewed
{{ count }}
import Vue from 'vue';
import VueResource from 'vue-resource';
Vue.use(VueResource);
import Demo from './components/demo.vue';
import Cat from './components/cat.vue';
import Cats from './components/cats.vue';
import CatCounter from './components/cat_counter.vue';
new Vue({
el: '#page',
components: {
Demo,
Cat,
Cats,
CatCounter
},
methods: {
ready() {
this.$on('new-cat', function(cat) {
this.$broadcast('new-cat', cat);
}, (response) => {
console.log('Error');
});
}
}
});
Demo