javascript - Vue for loop for objects not working -
i trying create top menu dropdown buttons when iterating on object looks this:
links: { store: 'store', language: [{'target': '/english'},{'target': '/norwegian'}], login: 'user/login' }
i have tried achieve making loop looks this:
<div v-for="(value, key) in links" :key="key" class="control"> <div v-if='array.isarray(value)'> <dropdown-menu :menu="value"></dropdown-menu> </div> <div v-else> <a :href="value"> {{ key }} </a> </div> </div>
but, errors:
property or method "value" not defined on instance referenced during render. make sure declare reactive data properties in data option.
even if declare value , key initial values of null, not rendering anything:
data() { return { data: null, value: null, key: null, }; },
this dropdown menu component:
<template> <div class="dropdown is-active"> <div class="dropdown-trigger"> <button class="button" aria-haspopup="true" aria-controls="dropdown-menu"> <span>dropdown button</span> <span class="icon is-small"> <i class="fa fa-angle-down" aria-hidden="true"></i> </span> </button> </div> <div class="dropdown-menu" id="dropdown-menu" role="menu"> <div class="dropdown-content"> <a href="#" class="dropdown-item"> dropdown item </a> <a class="dropdown-item"> other dropdown item </a> <a href="#" class="dropdown-item is-active"> active dropdown item </a> <a href="#" class="dropdown-item"> other dropdown item </a> <hr class="dropdown-divider"> <a href="#" class="dropdown-item"> divider </a> </div> </div> </div> </template> <script> export default { name: 'dropdown-menu', props: ['menu'], data() { return {}; }, }; </script>
but, dropdown menu not shown in vue dev tools when go top-bar component.
update
for reason if removed divs, , changed template this:
<dropdown-menu v-if='array.isarray(value)' :menu="link"></dropdown-menu> <a :href="value" v-else> {{ key }} </a>
if explain it, great.
Comments
Post a Comment