Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  78] [ 5]  / answers: 1 / hits: 52561  / 5 Years ago, thu, january 17, 2019, 12:00:00

I am trying to create some type of tree with vue.js and stuck on a problem with element props. Help me out plz.



I've tried :content={{tempCont}} and I've tried content={{tempCont}}, but none of them worked.



Here's the place where I am using tree element:



<div id=tree>
<treeItem :title=Parent :content={{tempCont}}></treeItem>
</div>


Here's the entire tree element:



<template>
<div>
<p v-on:click=openTree>{{title}}</p>
<div id=childs v-if=childVisibility>
<treeItem v-for=item in content :key=item title=item>
</div>
</div>
</template>

<script>
export default {
data: {
childVisibility: false
},

methods: {
openTree: function(){
childVisibility = !childVisibility;
}
},

props: {
title: String,
content: Array,
}
}
</script>

<style scoped>

</style>


I am getting this error:Error


More From » vue.js

 Answers
18

Ok so first of all, when you v-bind something like v-bind:title or :title, what you bind is expressed as a javascript expression.



So if you want your title attribute to be the string Parent, you need either to write it like a native html attribute title=Parent (notice the lack of :), or as a vue bound attribute v-bind:title='Parent' or :title='Parent' (notice the use of '' to express a string primitive type in javascript.



Now, the {{ variable }} syntax is used inside vuejs template but you do not need to use it inside v-bind attributes since they are already interpreted as javascript.



So you shouldn't write this:



<div id=tree>
<treeItem :title=Parent :content={{tempCont}}></treeItem>
</div>


but this instead:



<div id=tree>
<treeItem title=Parent :content=tempCont></treeItem>
</div>


SincetempCont is already a valid javascript expression.


[#52761] Thursday, January 10, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
albert

Total Points: 652
Total Questions: 105
Total Answers: 108

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;