Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vue.js__1_.pdf

 Vue.js__1_.pdf

Christian Nascimento

September 24, 2016
Tweet

More Decks by Christian Nascimento

Other Decks in Technology

Transcript

  1. var Example = Vue.extend({ template: '<div>{{ message }}</div>', data: function

    () { return { message: 'Hello Vue.js!' } } }) // register it with the tag <example> Vue.component('example', Example)
  2. // Angular 2 import { Component } from '@angular/core'; @Component({

    selector: 'my-component', template: '<div>Hello my name is {{name}}. <button (click)="sayMyName()">Say my name</button></div>' }) export class MyComponent { constructor() { this.name = 'Max'...
  3. <div id="app"> <input v-model="newTodo" v-on:keyup.enter="addTodo"> <ul> <li v-for="todo in todos">

    <span>{{ todo.text }}</span> <button v-on:click="removeTodo($index)">X</button> ...
  4. new Vue({ el: '#app', data: { newTodo: '', todos: [

    { text: 'Add some todos' } ] }, ...
  5. methods: { addTodo: function () { var text = this.newTodo.trim()

    if (text) { this.todos.push({ text: text }) this.newTodo = '' } },... http://vuejs.org/api/
  6. // Vue Router import Vue from 'vue'; import VueRouter from

    'vue-router'; import config from 'config'; Vue.use(VueRouter) const router = new VueRouter({history: true, root: config.root}); router.map({ '/': { name: 'home', component: view('home') }, });
  7. // JSX new Vue({ el: '#app', methods: { hello ()

    { alert('Hello!') } }, render (h) { return ( <h1 on-click={this.hello}>Hello from JSX</h1> ) ...
  8. // todobe/app/controllers/api/v1/todos_controller.rb module Api::V1 class TodosController < ApiController include ErrorSerializer

    before_action :set_todo, only: [:show, :update, :destroy] def index @todos = Todo.all render json: @todos end ...
  9. // JSON { "data": [ { "id": "6", "type": "todos",

    "attributes": { "title": "casadasd", "completed": false, "order": 2 ...
  10. // Main.js import Vue from 'vue'; import App from './App';

    import VueSweetAlert from 'vue-sweetalert' ; require('font-awesome/css/font-awesome.css' ); Vue.use(require( 'vue-resource' )); Vue.use(VueSweetAlert); new Vue({ el: 'body', components: { App }, });
  11. // App.vue <template> <div id="app"> <img class="logo" src="./assets/logo.png" > <todo></todo>

    </div> </template> <script> import Todo from './components/Todo' ; ...
  12. // Todo.vue ... <button v-on:click="addTodo" class="form-control" >Submit</button> <ul class="list-group" v-if="todos.length

    > 0" > <li v-for="todo in todos | orderBy 'attributes.order'" track-by="$index" class="list-group-item" > <todo-item :todolist ="todo"></todo-item> </li> </ul> </div> ...
  13. // TodoItem.vue import { API_BASE_URL } from '../../config/index.js' ; export

    default { props: ['todolist','fetchtodos' ], data() { return { isEditing: false, newTitle: '', }; }, methods: { editTodo() { this. $set('isEditing', true); },...