Answer the question
In order to leave comments, you need to log in
How to correctly write v-if directives in a template?
How to correctly write v-if directives in the template, provided that the data structure can be either a string or an array? those. in Data { return { ... can be like this "code": "one",
or like this "code": ["one", "two"],
In the template I write like this:
template: `
<template v-for="(value, index) in cd.code" :key="index">
<small class="tag">{{ value }}</small>
</template>
`
"code": "one",
, then "one" is split into 3 tagssmall
Answer the question
In order to leave comments, you need to log in
If not an array, convert to an array:
or make it a computed property:
computed: {
codeArray() {
return Array.isArray(cd.code) ? cd.code : [cd.code];
}
}
v-for="(value, index) in codeArray"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question