link1507 link1508 link1509 link1510 link1511 link1512 link1513 link1514 link1515 link1516 link1517 link1518 link1519 link1520 link1521 link1522 link1523 link1524 link1525 link1526 link1527 link1528 link1529 link1530 link1531 link1532 link1533 link1534 link1535 link1536 link1537 link1538 link1539 link1540 link1541 link1542 link1543 link1544 link1545 link1546 link1547 link1548 link1549 link1550 link1551 link1552 link1553 link1554 link1555 link1556 link1557 link1558 link1559 link1560 link1561 link1562 link1563 link1564 link1565 link1566 link1567 link1568 link1569 link1570 link1571 link1572 link1573 link1574 link1575 link1576 link1577 link1578 link1579 link1580 link1581 link1582 link1583 link1584 link1585 link1586 link1587 link1588 link1589 link1590 link1591 link1592 link1593 link1594 link1595 link1596 link1597 link1598 link1599 link1600 link1601 link1602 link1603 link1604 link1605 link1606 link1607 link1608 link1609 link1610 link1611 link1612 link1613 link1614 link1615 link1616 link1617 link1618 link1619 link1620 link1621 link1622 link1623 link1624 link1625 link1626 link1627 link1628 link1629 link1630 link1631 link1632 link1633 link1634 link1635 link1636 link1637 link1638 link1639 link1640 link1641 link1642 link1643

[Vue.js] Wait promise inside for loop Subscribe to RSS

let currentProduct;

for (let i = 0; i < products.length; i++) {
currentProduct = products[i];

subscription.getAll(products[i]._id)
.then((subs) => {
update(subs, currentProduct);
});
}

I’m using bluebird, the methods getAll and update return promises. How can I say “Wait until the two promises return, then update the currentProduct value”? I’m quite new to JS…

Solution :

This will be straightforward if you can use async/await:

// Make sure that this code is inside a function declared using
// the `async` keyword.
let currentProduct;

for (let i = 0; i < products.length; i++) {
currentProduct = products[i];

// By using await, the code will halt here until
// the promise resolves, then it will go to the
// next iteration…
await subscription.getAll(products[i]._id)
.then((subs) => {
// Make sure to return the promise here…
return update(subs, currentProduct);
});

// You could also avoid the .then by using two awaits:
/*
const subs = await subscription.getAll(products[i]._id);
await update(subs, currentProduct);
*/
}

Or if you can only use plain promises, you can loop through all the products, and put each promise in the .then of the last loop. In that way, it will only advance to the next when the previous has resolved (even though it will have iterated the whole loop first):

let currentProduct;

let promiseChain = Promise.resolve();
for (let i = 0; i < products.length; i++) {
currentProduct = products[i];

// Note that there is a scoping issue here, since
// none of the .then code runs till the loop completes,
// you need to pass the current value of `currentProduct`
// into the chain manually, to avoid having its value
// changed before the .then code accesses it.

const makeNextPromise = (currentProduct) => () => {
// Make sure to return the promise here.
return subscription.getAll(products[i]._id)
.then((subs) => {
// Make sure to return the promise here.
return update(subs, currentProduct);
});
}

// Note that we pass the value of `currentProduct` into the
// function to avoid it changing as the loop iterates.
promiseChain = promiseChain.then(makeNextPromise(currentProduct))
}

In the second snippet, the loop just sets up the entire chain, but doesn’t execute the code inside the .then immediately. the getAll functions won’t run until each prior one has resolved in turn (which is what you want).

Solution 2:

Here is how I’d do it:

for (let product of products) {
let subs = await subscription.getAll(product._id);
await update(subs, product);
}

No need to manually chain promises or iterate arrays by index :)

Solution 3:

You may want to keep track of what products you’ve processed because when one fails you have no idea how many succeeded and you don’t know what to correct (if roll back) or retry.

The async “loop” could be a recursive function:

const updateProducts = /* add async */async (products,processed=[]) => {
try{
if(products.length===0){
return processed;
}
const subs = await subscription.getAll(products[0]._id)
await update(subs, product);
processed.push(product[0]._id);
}catch(err){
throw [err,processed];
}
return await updateProducts(products.slice(1),processed);
}

Without async you can use recursion or reduce:

//using reduce
const updateProducts = (products) => {
//keep track of processed id’s
const processed = [];
return products.reduce(
(acc,product)=>
acc
.then(_=>subscription.getAll(product._id))
.then(subs=>update(subs, product))
//add product id to processed product ids
.then(_=>processed.push(product._id)),
Promise.resolve()
)
//resolve with processed product id’s
.then(_=>processed)
//when rejecting include the processed items
.catch(err=>Promise.reject([err,processed]));
}

//using recursion
const updateProducts = (products,processed=[]) =>
(products.length!==0)
? subscription.getAll(products[0]._id)
.then(subs=>update(subs, product))
//add product id to processed
.then(_=>processed.push(products[0]._id))
//reject with error and id’s of processed products
.catch(err=>Promise.reject([err,processed]))
.then(_=>updateProducts(products.slice(1),processed))
: processed//resolve with array of processed product ids

Here is how you’d call updateProducts:

updateProducts(products)
.then(processed=>console.log(“Following products are updated.”,processed))
.catch(([err,processed])=>
console.error(
“something went wrong:”,err,
“following were processed until something went wrong:”,
processed
)
)

[Vue.js] Vue.js call component method results in an error Subscribe to RSS

The problem is the following, I basically have one Component which is ‘card’ and I the cards are rendered inside a vue.js called ‘dash’ using v-for. Now what I try to do is add an on-click event to the card, and there is a method called expand declared inside my Component but I get an error when I try to do so.
My HTML code looks like this

<div id=”dash” class=”dash” style=”margin-left: 350px; margin-top:50px;”>
<div v-for=”state in states” class=”state slide-in-fwd-center” v-bind:style=”{‘margin-left’ : state.margin + ‘px’}”>
<h3 class=”header”>{state.state}</h3>
<card v-for=”card in state.cards” v-bind:overall_progress=”card.overall_progress” v-bind:test_progress=”card.test_progress” v-bind:status=”card.status” v-bind:practice_progress=”card.practice_progress” v-bind:due_date=”card.due_date” v-bind:study_progress=”card.study_progress” v-bind:key=”card.id” v-bind:description=”card.description”
v-bind:title=”card.title” @click=”$emit(‘expand’)”></card>
</div>
</div>

The outer div “dash” is a Vue, that has stated and each state holds an array of cards which are vue.js Components. The component looks like this

Vue.component(“card”, {
props: [
“title”,
“description”,
“due_date”,
“study_progress”,
“practice_progress”,
“test_progress”,
“overall_progress”,
“status”
],
template: `TEMPLATE CODE HERE`,
methods: {
calcColor: function(value) {
if(value > 89){
return ‘bg-success’
}
else if(value < 90 && value > 39){
return ‘bg-info’
}
else{
return ‘bg-danger’
}
},
expand : function(){
console.log(‘123’)
}
}
});

While the dash is really simple:

var dash = new Vue({
el: “#dash”,
data: {
states: []
}
});

when not sure what might be the problem since the method when trying to call is defined inside the methods:{} of the Component ‘card’ itself it is not in the vue.js or global function

Solution :

firstly it might be easier for you to bind just the whole card object and access it on card component. So instead of this:

<div id=”dash” class=”dash” style=”margin-left: 350px; margin-top:50px;”>
<div
v-for=”state in states”
class=”state slide-in-fwd-center”
v-bind:style=”{‘margin-left’ : state.margin + ‘px’}”
\>
<h3 class=”header”>{ state.state }</h3>
<card
v-for=”card in state.cards”
v-bind:overall_progress=”card.overall_progress”
v-bind:test_progress=”card.test_progress”
v-bind:status=”card.status”
v-bind:practice_progress=”card.practice_progress”
v-bind:due_date=”card.due_date”
v-bind:study_progress=”card.study_progress”
v-bind:key=”card.id”
v-bind:description=”card.description”
v-bind:title=”card.title”
@click=”$emit(‘expand’)”
\></card>
</div>
</div>

you will have that:

<div id=”dash” class=”dash” style=”margin-left: 350px; margin-top:50px;”>
<div v-for=”state in states” class=”state slide-in-fwd-center” v-bind:style=”{‘margin-left’ : state.margin + ‘px’}”>
<h3 class=”header”>{state.state}</h3>
<card v-for=”card in state.cards”
v-bind:card = “card”
@click=”$emit(‘expand’)”></card>
</div>
</div>

For the event, don’t use the $emit, try just to call expand, like this:

@click=”event_name(argument1, argument2)”

so - for the case:

@click=”expand”

Be sure, that you define expand method in the component, you are using it.
in this case - in the parent component, not in the card.

[Vue.js] How to show item from click without calling a method in vue.js? Subscribe to RSS

to click a job.id and then have it display list (name of job.names) below

Here is the example from a table

<td>
<ul>
<template v-for=’job in jobs’>
<li @click=”show list below job.id”>{ job.id } </li>
</template>
</ul>
</td>

How to I show name of job.names when i click on a job.id?

Solution :

I not really konw what do you want to do. do you want to click job.id to toggle job detail just like this?

<ul>
<template v-for=’job in jobs’>
<li>
<span @click=’showJob=job.id’>{job.id}</span>
<ul :class=”[showJob===job.id?’show’:’hide’]“>
<li v-for=’name in job.names’>{name}</li>
</ul>
</li>
</template>
</ul>

Solution 2:

you want to do it with a method? ok how about this

data(){
return {

jobNames : []
}
}
showList(i) {
// if you wanna show them on console
console.log(this.jobs[i].names)
// if you wanna show them on the DOM
this.jobNames = this.jobs[i].names;
}
<td>
<ul>
<template v-for=’(job,i) in jobs’>
<li @click=”showList(i)”>{ job.id } </li>
</template>
</ul>
</td>

<!– you can place this anywhere you want inside the component template –>

<ul>
<li v-for=’name in jobNames’>{name}</li>
</ul>

[Vue.js] How get response from express server for ajax query in nuxtjs Subscribe to RSS

I’m want to get data from the node/express server after send ajax query from any page of the nuxtjs app.
Usually, for getting and sending ajax query in PHP server, I’m do like this $_GET[‘var’]; echo json_encode(‘Server got data’);
Now to use node server express for saving data in mongodb.
When I trying to send a query, response return full code of file test.js.

File index.vue

methods: {
onServer() {
this.$axios.get(‘/server/test’).then(res => {
console.log(‘res’, res.data)
})
}
}

File test.js

var express = require(‘express’);
var app = express();

app.get(‘*‘, function (req, res) {
res.send(‘Hello World!’);
});

app.listen(3000, function () {
console.log(‘Example app listening on port 3000!’);
});

File server/index.js

const express = require(‘express’)
const consola = require(‘consola’)
const { Nuxt, Builder } = require(‘nuxt’)
const app = express()

// Import and Set Nuxt.js options
const config = require(‘../nuxt.config.js’)
config.dev = !(process.env.NODE_ENV === ‘production’)

async function start() {
// Init Nuxt.js
const nuxt = new Nuxt(config)

const { host, port } = nuxt.options.server

// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
} else {
await nuxt.ready()
}

// Give nuxt middleware to express
app.use(nuxt.render)

// Listen the server
app.listen(port, host)
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true
})
}
start()

I’m a new user node, please help me!

Solution :

the main issue is that you are targeting “test.js” in the axios url. This is why it responds with the file rather than what the get route should respond with.

So try with:

this.$axios.get(‘http://nuxt-profi/server/test').then(…

and see what you get. You should also be able to access that in the browser, just go to the url http://nuxt-profi/server/test and it should show the “Hello World” reponse.

However I can’t be sure how you have set all this up. Are you running this as development? In which case maybe you should access it as http://localhost:3000/server/test but maybe you have virtual hosts configured like this. Also, is this a separate backend api or are you trying this as server middleware?

If this doesn’t help please give us more info about the project setup and we’ll go from there.

[Vue.js] Import page component alternative vue.js Subscribe to RSS

I’m using a plain PHP site with vue.js and want to import components, As I see import only works for node and vue?
Is there a solution?
I’m really not that good.

import and require js pages

import settings from ‘settings.html’;
Vue.component(‘app-settings’, settings);
import Form from ‘settings.js’;
<script src=”https://cdn.jsdelivr.net/npm/vue"></script>

Uncaught SyntaxError: Unexpected identifier

Solution :

VueJS built on the top of ES6, so vuejs require babel in order to work.
Note: I really do not know why you want to use vuejs and plain PHP,
you should make a PHP API, API that provides data for front-end,
you cannot use PHP and VueJS in one file because of vuejs code must pass on babel.
you should make a PHP API (RESTful API or Graphql), and you will fetch data from API to the front by using axios, fetch or Apollo or whatever.

[Vue.js] vuejs test component with properties inside parent element Subscribe to RSS

I’m test a custom component with vue.js test utils and Jest. My component uses Vuetify component, and so I need to declare a div with data-app attribute, in order to have the menu rendered (if I dont, I get the following error :

wrapper = mount(MyComponent, {
propsData: {
value: 1
});

[Vuetify] Unable to locate target [data-app]

If my component didn’t use any properties, I would do like this:

wrapper = mount(Vue.extend({
template: `<div data-app=”true”><MyComponent /></div>`,
}), {
attachToDocument: true
});

But, then, I can’t set component properties, can I?

So I thought about using parentComponent property like this:

const parent = {
template: `<div data-app=”true”><MyComponent /></div>`,
};

wrapper = mount(MyComponent, {
parentComponent: parent,
propsData: {
value: 1’
});

But it does not work either.

Is there any way to test my component?

Solution :

The solution I found was not to use parentComponent, but define an ad hoc component for testing. For example if my component has 2 props prop1 and prop2

wrapper = mount(Vue.extend({
template: `<div data-app=”true”><MyComponent :prop1=prop1 :prop2=prod2 /></div>`,
}), {
attachToDocument: true,
props: [‘prop1’, ‘prop2’],
propsData: [‘value1’, ‘value2’]
});

[Vue.js] Return response from VUEX actions to component Subscribe to RSS

So there is a component which has this method:

const message = {
title: this.title,
message: this.message,
receiver: this.username
}
this.$store.dispatch(‘contactAuthor’, message);

then this happens in actions.js:

const contactAuthor = ({commit}, payload) => {
API.post(‘send-message’, payload).then((response) => {
if(response.status === 200 && response.data.success) {
// WHAT TO RETURN HERE TO SET SUCCESS TO TRUE IN COMPONENT?
} else {
console.log(‘Something went wrong’);
}
}).catch((error) => {
console.log(‘Something went wrong’);
});
}

Now my component has data called success: false and to set it to true when I call the function from actions.js contactAuthor. How can I return true and set it to data success in component ?

Solution :

Personally I feel sending the data back to the component is not the ideal way. Instead, you can have another constant (like below) in actions.js and have a getter for the same. Access the getter in the component as a computed property.

// actions.js
const state = {
api: {
fetch: {
inProgress: false,
completed: false,
success: false,
error: false,
},
data: {}
}
}

const getter = {
‘API_DATA’: state => {
return state.api
}
}

const mutations = {
‘SET_API_DATA_FETCH_IN_PROGRESS’: state => {
state.api.fetch.inProgress = true
state.api.fetch.completed = false
state.api.fetch.success = false
state.api.fetch.error = false
state.api.data = {}
},
‘SET_API_DATA_FETCH_SUCCESS’: (state, payload) => {
state.api.fetch.inProgress = false
state.api.fetch.completed = true
state.api.fetch.success = true
state.api.fetch.error = false
state.api.data = payload
},
‘SET_API_DATA_FETCH_ERROR’: (state, payload) => {
state.api.fetch.inProgress = false
state.api.fetch.completed = true
state.api.fetch.success = false
state.api.fetch.error = true
state.api.data = payload
}
}

const contactAuthor = ({ commit }, payload) => {
commit(‘SET_API_DATA_FETCH_IN_PROGRESS’)
API.post(‘send-message’, payload).then((response) => {
if (response.status === 200 && response.data.success) {
// WHAT TO RETURN HERE TO SET SUCCESS TO TRUE IN COMPONENT?
commit(‘SET_API_DATA_FETCH_SUCCESS’, response)
} else {
commit(‘SET_API_DATA_FETCH_ERROR’, response)
console.log(‘Something went wrong’);
}
}).catch((error) => {
commit(‘SET_API_DATA_FETCH_ERROR’, response)
console.log(‘Something went wrong’);
});
}

// component.vue
computed: {
apiDataFetchSuccess() {
return this.$store.getters.API_DATA.fetch.success
},
apiData() {
return this.$store.getters.API_DATA.data
}
}

Solution 2:

Okay so this worked.

const contactAuthor = (payload) => {
return API.post(‘send-message’, payload).then((response) => {
if(response.status === 200 && response.data.success) {
const trueMessage = true;
return trueMessage;
} else {
console.log(‘Something went wrong’);
}
}).catch((error) => {
console.log(‘Something went wrong’);
});
}

returning promise from axios and then returning trueMessage from contactAuthor and then setting it up like this in component:

this.$store.dispatch(‘contactAuthor’, message).then(data => {
this.success = data;
});

[Vue.js] Vue Router return 404 when revisit to the url Subscribe to RSS

I just enable vue.js router history mode. And it work fine when I visit to vue.js routing via v-href or href. But, when I try to refresh that page or go directly from browser address bar, it just return 404. Is there any option to accept refresh/revisit to that url?

The following is my vue.js router configuration

var router = new VueRouter({
hashbang: false,
history: true,
mode: ‘html5’,
linkActiveClass: “active”,
root: ‘/user’
});

Solution :

By refreshing the page you are making a request to the server with the current url and the server returns 404. You have to handle this on the web framework or web server level.

https://router.vuejs.org/en/essentials/history-mode.html

Solution 2:

I think you are missing that SPA is not server side rendering. At least for the majority. So, when you access /anything the web server won’t redirect it to index.html. However, if you click on any vuejs router link, it will work due to the fact that the javascript got in action, but not the server side.

To solve this, use .htaccess and redirect all requests to index.html like so

<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</ifModule>

Hope it helps someone!

Solution 3:

If someone is dealing with this issue in .NET Core as the backend of the app, a nice approach is a simple fallback handler in the Startup.cs of our .NET Core application:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
….the configuration
app.UseMvc(routes =>
{
routes.MapRoute(
name: “default”,
template: “{controller=Home}/{action=Index}/{id?}”);
});
//handle client side routes
app.Run(async (context) =>
{
context.Response.ContentType = “text/html”;
await context.Response.SendFileAsync(Path.Combine(env.WebRootPath, “index.html”));
});
}
}

For more details: http://blog.manuelmejiajr.com/2017/10/letting-net-core-handle-client-routes.html

Solution 4:

For someone seeing this using an Express backend, there is the middleware connect-history-api-fallback that is implemented like this

const express = require(‘express’);
const history = require(‘connect-history-api-fallback’);

const app = express();
app.use(history({
index: ‘/‘ //whatever the home/index path is default is /index.html
}));

Or with Native Node

const http = require(‘http’)
const fs = require(‘fs’)
const httpPort = 80

http.createServer((req, res) => {
fs.readFile(‘index.htm’, ‘utf-8’, (err, content) => {
if (err) {
console.log(‘We cannot open “index.htm” file.’)
}

res.writeHead(200, {
‘Content-Type’: ‘text/html; charset=utf-8’
})

res.end(content)
})
}).listen(httpPort, () => {
console.log(‘Server listening on: http://localhost:%s', httpPort)
})

Both are suggestions in the documentation.

Solution 5:

Anyone else facing the same problem, I just realized that

“book/:bookId/read” // this will not work after page reload

and this are different

“/book/:bookId/read” // this is what works even after page reload

This is of course after following what other fellas have suggested up there more importantly the catch all route in the app server side.
I actually don’t know why this worked, but any one with any ideas can let us know.

Solution 6:

If you don’t really care about the hash in the url, you can just set the mode to hash in you router configuration file: mode: ‘hash’
That works fine without the need to setting up the server side.

[Vue.js] Vue v-for click not show correcly element Subscribe to RSS

for` to show data from database:

<div v-for=”item in resourceList” :key=”item.id”>
<input :id=”roomData.id” type=”checkbox” @click=”saveCheckbox”>
<label :for=”roomData.id”>{ item.question }</label>

//calendar
<span v-if=”active”>
<datepicker v-model=”date”></datepicker>
</span>
<span v-else id=”disableCalendar”>Not show calendar</span>
</div>

there is problem with function click. For example on page v-for show 10 elements. In each element there will be a button to click @click=”saveCheckbox”.

Function in methods:

saveCheckbox(e){
if(e.target.checked) {
this.active = true;
} else {
this.active = false;
}
}

In data I have:

active = false;

Now when user click in for example first element button, the calendar will appear in EACH element.
How I can show calendar ONLY in element which user clicked ?

Solution :

You need to store the value for each item in the loop. With this.active = true you have only one state which you use for every item in the loop.

Example:

new Vue({
el: “#app”,
data: {
isActive: [false, false, false, false]
},
methods: {
toggleActive(index) {
this.$set(this.isActive, index, !this.isActive[index])
}
}
})
<script src=”https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id=”app”>
<div v-for=”(active, index) in isActive” :key=”index”>
{ active } { index }
<button type=”button” @click=”toggleActive(index)”>Toggle</button>
</div>
</div>

Solution 2:

The active variable is shared for each item in the resourceList, you need to create active identifier for each item in the list, one way to do it is to have active property of item of resourceList. Assuming you have active property in each item of resourceList, you can do the following.

<div v-for=”item in resourceList” :key=”item.id”>
<input :id=”roomData.id” type=”checkbox” @click=”saveCheckbox(item)”>
<label :for=”roomData.id”>{ item.question }</label>

//calendar
<span v-if=”active”>
<datepicker v-model=”date”></datepicker>
</span>
<span v-else id=”disableCalendar”>Not show calendar</span>
</div>

And the saveCheckbox method

saveCheckbox(item){
item.active = !item.active
}

[Vue.js] Vue Component Communication (Parent > Children) Subscribe to RSS

there is a parent component (todo-list) with a child component inside (todo-item). when trying to create a checkbox(check all todos) in the parent so that when all todos will be checked with one click.

With the checkAll() in the parent component, it change the props of the child but it does not change the data of the child.

This is the parent component todo-list

<template>
<div class=”todo-list-container”>
<todo-input @addTodo=”addTodo”></todo-input>
<todo-item v-for=”(todo, index) in todos”
:key=”todo.id”
:todo=”todo”
:index=”index”
:completed=”todo.completed”
@removeTodo=”removeTodo”
@changedCompleted=”changedCompleted”
\></todo-item>
<div class=”flex-container”>
<div class=”button-aux-div”></div>
<a href=”#” class=”todo-button”>
<input type=”checkbox” :checked=”!anyRemaining” @change=”checkAll”>
</a>
</div>
</div>
</template>

<script>

import vue.js from ‘vue’
import TodoItem from ‘./TodoItem’
import TodoInput from ‘./TodoInput’

export default {
name: ‘todo-list’,

components: {
TodoItem,
TodoInput,
},

data () {
return {
idForTodo: 3,
todos: [
{
‘id’: ‘1’,
‘title’: ‘title1’,
‘body’: ‘body1’,
‘completed’: false,
},
{
‘id’: ‘2’,
‘title’: ‘title2’,
‘body’: ‘body2’,
‘completed’: false,
},
],
allChecked: false,
}
},

computed: {
remaining() {
return this.todos.filter(todo => !todo.completed).length
},
anyRemaining() {
return this.remaining != 0
}
},

methods: {
addTodo(todoMessage) {
this.todos.push({
id: this.idForTodo,
title: ‘title’ + this.idForTodo,
body: todoMessage,
completed: false,
})

this.idForTodo++;
},

removeTodo(data) {
this.todos.splice(data.index, 1);
this.idForTodo–;
},

changedCompleted(data) {
this.todos.splice(data.index, 1, data.todo)
},

checkAll() {
this.todos.forEach((todo) => todo.completed = event.target.checked)
},
},

}
</script>

This is the child componenet todo-item

<template>
<div class=”todo-item-container”>
<div class=”todo-title-container”>
<div class=”todo-id-container”>
<div id=”todo-id”>
<h2>{ id }</h2>
</div>
</div>
<div id=”todo-title”><h2>{ title }</h2></div>
<div class=”todo-completed-container”>
<a href=”#” class=”todo-button”>
<input type=”checkbox” v-model=”completed” @change=”changedCompleted”>
</a>
</div>
<div class=”todo-delete-container”>
<a href=”#” class=”todo-button” @click=”deletedTodo”></a>
</div>
</div>

<hr>

<div class=”todo-body-container”>
<p id=”todo-body”>{ body }</p>
</div>
</div>
</template>

<script>
export default {
name: ‘TodoItem’,

props: {
todo : {
type: Object,
required: true,
},
index : {
type: Number,
required: true,
},
},

data () {
return {
‘id’: this.todo.id,
‘title’: this.todo.title,
‘body’: this.todo.body,
‘completed’: this.todo.completed,
}
},

methods: {

deletedTodo() {
this.$emit(‘removeTodo’, {
‘index’: this.index,
‘todo’: {
‘id’: this.id,
‘title’: this.title,
‘body’: this.body,
‘completed’: this.completed,
}
})
},

changedCompleted() {
this.$emit(‘changedCompleted’, {
‘index’: this.index,
‘todo’: {
‘id’: this.id,
‘title’: this.title,
‘body’: this.body,
‘completed’: this.completed,
}
})
},
},
}

</script>

Solution :

Instead of ‘completed’: this.todo.completed, .
Use

computed: {
completed () {
return this.todo.completed
}
}