• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vue for Meteor

Meteor-Vue Build Status

Get Started

Meteor-Vue is the bridge between Vue.js [vuejs/vue] and Meteor. Vue.js is a very sleek and fast framework that works with descriptive bidirectional html data-binding. It also offers animation and transition to your app. Meteor-Vue combines them by offering the data-sync option.

Installation. For [email protected] or later,

meteor add vue:vue

Usage

First you need to instantiate var vm = new Vue({}) with option sync, which is linked with any reactive source from Meteor:

sync: {
    'some-key': function(){
        // It should return a reactive source
    }
}

The function should contain any kind of reactive sources from Meteor. For example,

var vm = new Vue({
        el: '#vue-demo',
        data: {
            'data1': 'data1',
            'data2': [1, 2, 3]
        },
        sync: {
            'data3': function() {
                return Posts.find()
            },
            'data4': function() {
                return Posts.find().fetch();
            },
            'data5': function() {
                return Posts.findOne();
            },
            'data6': function() {
                return Session.get('DOM-title')
            }
        }
});

After the instantiation of vm, the sync property automatically maps all its functions' return value into vm and vm.$data, which means one can access these data like:

var data3 = vm.data3
var data4 = vm.data4

// or some HTML
<div v-for="post in data3">
    [[post.title]]
</div>

A full example with html and collection definition here.

model.js

Posts = new Meteor.Collection('posts');

client/home.js

Template.home.rendered = function() {
    var vm = new Vue({
        el: '#vue-demo',
        data: {
            'name': 'Neil Armstrong',
            'arrayOfNumbers': [1, 2, 3]
        },
        sync: {
            'posts': function() {
                return Posts.find();
            }
        }
    });
}

client/home.html, note that [[...]] are used here instead of {{...}} to avoid the syntax conflicts.

<div id="vue-demo">

My name is [[name]]

<ul>
    <li v-for="number in arrayOfNumbers">
        Number: [[number]]
    </li>
</ul>

<ul>
    <li v-for="post in posts">
        [[post.tiltle]], [[post.content]]
    </li>
</ul>
</div>

API

If you want to dynamically bind more reactive data source, use the following api:

vm.$sync(key, func);
vm.$unsync(key);

Meteor-Vue Components

Define your component with <script type="text/x-template"> template:

<body>
    {{> home}}
</body>

<template name="home">

    <script type="text/x-template" id="hi-template">
        Hi, [[name]]

        <h2>Posts Summary</h2>
        <ul>
            <li v-for="post in posts" :post="post">[[post.title]]</li>
        </ul>
    </script>

    <div id="app">
        <hi></hi>
    </div>

</template>

Register your component with Vue.component() and then initialize your Vue view model.

if (Meteor.isClient) {
    Template.home.onRendered(function(){
        Vue.component('hi', {
            template: '#hi-template',
            data: function(){
                return {
                    name: 'Meteor-Vue'
                }
            },
            sync: {
                posts: function () {
                    return Posts.find({});
                }
            },
        })
        var vm = new Vue({
            el: '#app'
        })
    })
}

LICENSE

MIT

More Repositories

1

hast

Hast, an on-the-fly presentation for everyone! Realtime broadcasting and hot push changes. Using Meteor, DeckJS, aceEditor, etc
CSS
103
star
2

conditions

Minimalist rules engine for Golang
Go
31
star
3

meteor-nprogress

NProgress for Meteor
JavaScript
27
star
4

meteor-reactive-coffee

Reactive-Coffee for Meteor
JavaScript
16
star
5

knockout-client

Knockout Client for Meteor
JavaScript
12
star
6

docker-passenger-meteor

Docker image for easily deploying meteor, using fig.sh, passenger
Shell
7
star
7

reactive-coffee-demo

reactive-coffee-demo.meteor.com
CSS
5
star
8

meteor-deb

Deb.js for Meteor
JavaScript
3
star
9

docker-shakedown

Shakedown docker image for curl-based integration testing
Dockerfile
3
star
10

hast-electron

Hast markdown presentation in Electron
JavaScript
3
star
11

DM_GReader

Data mining upon personal Google Reader
Python
3
star
12

meteor-moot

Moot for Meteor
CSS
2
star
13

knockout-client-pager

pager.js integrated with with Meteor, creating subpages using Knockout.
JavaScript
2
star
14

meteor-kramed

Kramed for Meteor, a markdown (kramdown compatible) parser and compiler.
JavaScript
2
star
15

cpu_simulator

A tiny cpu simulator for architecture
Java
1
star
16

Greplin_Programming_Challenge

Python
1
star
17

Facebook_Newsletter

A firefox add-on for facebook newsletter
JavaScript
1
star
18

lcdaily

Send random leetcode email every day
HTML
1
star
19

iso8601ms

Package iso8601 is a simple Go package for encoding `time.Time` in JSON in ISO 8601 format with millisecond precision, with the converted UTC timezone
Go
1
star
20

meteor-bxslider

bxslider-4 for Meteor
JavaScript
1
star
21

meteor-state-machine

Javascript state machine for Meteor
JavaScript
1
star
22

meteor-garlic

Automatically persist your forms' text field values locally, Meteor wrapper of garlicjs
JavaScript
1
star