0

I'm new to vue.js and I'm trying to follow this course, and I can see that he got the data to displayed.

enter image description here

App.vue

<template>
    <div class="container">
        <Header title="Task Tracker" />
        <Tasks :tasks="tasks" />
    </div>
</template>

// --------------------------------------

<script>
import Header from "./components/Header.vue"
import Tasks from "./components/Tasks.vue"

export default {
    name: "App",
    components: {
        Header,
        Tasks
    },
    data() {
        return {
            tasks: []
        }
    },
    created() {
        this.tasks = [
            {
                id: "1",
                text: "Doctors Appointment",
                day: "March 5th at 2:30pm",
                reminder: true
            },
            {
                id: "2",
                text: "Meeting with boss",
                day: "March 6th at 1:30pm",
                reminder: true
            },
            {
                id: "3",
                text: "Food shopping",
                day: "March 7th at 2:00pm",
                reminder: false
            }
        ]
    }
}
</script>

// --------------------------------------

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
}
</style>

Header.vue

<template lang="">
    <header>
        <h1>
            {{ title }}
            <Button text="Add Task" color="green" />
            <Button text="Update Task" color="blue" />
            <Button text="Delete Task" color="red" />
        </h1>
    </header>
</template>

// --------------------------------------

<script>
import Button from "./Button.vue"

export default {
    name: "Header",
    props: {
        title: String
    },
    components: {
        Button
    }
}
</script>

// --------------------------------------

<style scoped>
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
</style>

Tasks.vue

<template lang="">
    <div :key="task.id" v-for="task in tasks">
        <Task :task="task" />
    </div>
</template>

// --------------------------------------

<script>
import Task from "./Task.vue"

export default {
    name: "Tasks",
    props: {
        tasks: Array
    },
    component: {
        Task
    }
}
</script>

Task.vue

<template lang="">
    <div class="task">
        <h3>{{ task.text }}</h3>
        <p>{{ task.day }}</p>
    </div>
</template>

// --------------------------------------

<script>
export default {
    name: "Task",
    props: {
        task: Object
    }
}
</script>

<style scoped>
.task {
    background: chocolate;
}

.task .reminder {
    border: 5px solid green;
}
</style>

Button.vue

<template>
    <button :style="{ background: color }" class="btn" @click="onClick()">
        {{ text }}
    </button>
</template>

// --------------------------------------

<script>
export default {
    name: "Button",
    props: {
        text: String,
        color: String
    },
    methods: {
        onClick() {
            console.log("click")
        }
    }
}
</script>

// --------------------------------------

<style></style>

What did I forget ? I'm not sure why I can't get my JSON data to display, I kept getting

enter image description here

1 Answer 1

2

In tasks.vue you have an error. Replace component:{ with components:{

Sign up to request clarification or add additional context in comments.

7 Comments

Wow, you're correct. How do you spot so quick ? A typo like this why doesn't the compiler in VSCode let it slip ?
Is there a plugin I should download to be able to catch something like this in the future by myself ?
I do not use VSCode but ESLint helps prevents this kind of errors. Then you need this plugin for Vue: eslint.vuejs.org
Let me look into those, do you lint all the time on save ?
Yes I do. I also let it run in my webpack configuration while running dev server so I can get feedback while developing.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.