Vue computed properties are not being called.
Here is the code :
import Assignment from "./Assignment.js";
export default {
components: { Assignment },
template: `
<section v-show="assignments.length">
<h2 >{{ title }}
<span>({{assignments.length}})</span>
</h2>
<div >
<button v-for="tag in tags" border rounded px-1 py-px font-5 ></button>
</div>
<ul >
<assignment
v-for="assignment in assignments"
:key="assignment.id"
:assignment="assignment"
></assignment>
</ul>
</section>
`,
props: {
assignments: Array,
title: String
},
computed: {
tags() {
return ('science', 'math', 'reading')
//The return is not returning
}
}
}
I can not return computed properties to button with even v-for
CodePudding user response:
I think, you made a typo
tags() {
// return an array
return ['science', 'math', 'reading']
}
instead of
tags() {
// will return 'reading' only.
return ('science', 'math', 'reading')
}
Also, you need to a text for the button.
<div >
<button v-for="tag in tags" border rounded px-1 py-px font-5 >{{tag}}</button>
</div>