Giter VIP home page Giter VIP logo

learning-vuejs's People

Contributors

amitavroy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learning-vuejs's Issues

cannot split TODO in components

I like your vue tutorial. But I am stuck on the topic of splitting ToDoApp in separate components.
Please help me to understand what's wrong with the code.

I have Laravel 5.3 + vuejs 2.0.5

This way ToDoApp is working
\resources\assets\js\app.js

require('./bootstrap');
const app = new Vue({
    el: '#app',
    data: {
    	todos: [],
    	newTodo: {id: null, title: '', completed: false},
	},
	computed: {
	  	todoCount() {
	    	return this.todos.length
	    }
	},
	methods: {
	  	addNewTodo(newTodo) {
	    	this.todos.push(newTodo)
	    	this.newTodo = {id: null, title: '', completed: false}
	    },
	    
	    deleteTodo(todo) {
	        var index = this.todos.indexOf(todo);
	        this.todos.splice(index, 1);
	    },

	    todoCompleted(todo) {
	    	todo.completed = !todo.completed
	    },
	}
});

blade.php

        <div class="col-sm-12">
            <div class="panel panel-default">
                <div class="panel-heading" >Мои задачи @{{todoCount}}</div>

                <div class="panel-body">
                    <ul class="list-group" v-if="todos.length > 0">
                        <li class="list-group-item" v-for="todo in todos" v-bind:class="{ 'completed' : todo.completed }">
                            @{{ todo.title }}
                            <button class="btn btn-warning btn-xs pull-right" v-on:click="deleteTodo(todo)">Удалить</button>
                            <button class="btn btn-xs pull-right margin-right-10" 
                                v-bind:class="{'btn-success' : todo.completed, 'btn-danger' : !todo.completed}"
                                v-on:click="todoCompleted(todo)">@{{ todo.completed ? 'Завершено' : 'В работе' }}</button>
                        </li>
                    </ul>
                    <div v-else>Задач нету</div>
                    <form v-on:submit.prevent="addNewTodo(newTodo)">
                            <input v-model="newTodo.title" type="text" class="form-control margin-right-10" placeholder="добавь новую задачу">
                            <button class="btn btn-success">Добавить</button>
                    </form>

                </div>
            </div>
        </div>

but when I try to split the code into components I get the error in console
\resources\assets\js\app.js

require('./bootstrap');

Vue.component('TodoItems', require('./components/TodoItems.vue'));
Vue.component('TodoAddForm', require('./components/TodoAddForm.vue'));

const app = new Vue({
    el: '#app',
    data: {
    	todos: [],
    	newTodo: {id: null, title: '', completed: false},
	},
});

\resources\assets\js\components\TodoItems.vue

<template>
    <ul class="list-group" v-if="todos.length > 0">
        <li class="list-group-item" v-for="todo in todos" v-bind:class="{ 'completed' : todo.completed }">
            {{ todo.title }}
            <button class="btn btn-warning btn-xs pull-right" v-on:click="deleteTodo(todo)">Удалить</button>
            <button class="btn btn-xs pull-right margin-right-10" 
                v-bind:class="{'btn-success' : todo.completed, 'btn-danger' : !todo.completed}"
                v-on:click="todoCompleted(todo)">{{ todo.completed ? 'Завершено' : 'В работе' }}</button>
        </li>
    </ul>
    <div v-else>Задач нету</div>
</template>

<script>
    export default {
        props: ['todos'],

        computed: {
            todoCount() {
                return this.todos.length
            }
        },

        methods: {
            todoCompleted(todo) {
                todo.completed = !todo.completed
            },

            deleteTodo(todo) {
                var index = this.todos.indexOf(todo);
                this.todos.splice(index, 1);
            },

        }

    }
</script>

\resources\assets\js\components\TodoAddForm.vue

<template>
        <form class="form-group" v-on:submit.prevent="addNewTodo(newTodo)">
            <input v-model="newTodo.title" type="text" class="form-control margin-right-10" placeholder="добавь новую задачу">
            <button class="btn btn-success">Добавить</button>
        </form>
</template>

<script>
    export default {
      props: ['newtodo'],
      
      data() {
        return {
            todo: {id: null, title: '', completed: false}
        }
      },
      
      methods: {
        addTodo() {
          this.newtodo = this.todo;
          this.todo = {id: null, title: '', completed: false};
        }
      }


    }
</script>

blade.php

                <div class="panel-body">
                    <TodoItems>  </TodoItems> 
                    <TodoAddForm>  </TodoAddForm>
                </div>

error in console

[Vue warn]: Property or method "todoCount" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. 
(found in root instance)app-1a9b4db40d.js%20line%20108%20%3E%20eval:2643:7

[Vue warn]: Unknown custom element: <todoitems> - did you register the component correctly? For recursive components, make sure to provide the "name" option. 
(found in root instance)app-1a9b4db40d.js%20line%20108%20%3E%20eval:2643:7

[Vue warn]: Unknown custom element: <todoaddform> - did you register the component correctly? For recursive components, make sure to provide the "name" option. 
(found in root instance)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.