我无法将数据从父级传递给子级.我正在使用道具,也试过返回数据 - 没有运气.我有一个面板组件(它是父组件)与数据和panelBody组件(子)
小组如下:
<template>
<div id="panel">
<div class="panel">
<ul>
<li v-for="shelf in shelfs">
<panel-body :shelf="shelf" :selected.sync="selected"></panel-body>
</li>
</ul>
</div>
</div>
</template>
<script>
import PanelBody from '../components/PanelBody'
export default {
name: 'panel-body',
components: {
'panel-body': PanelBody
},
data: () => ({
shelfs: [{
name: 'shelf 1',
books: [{
title: 'Lorem ipum'
}, {
title: 'Dolor sit amet'
}]
}, {
name: 'shelf 2',
books: [{
title: 'Ipsum lorem'
}, {
title: 'Amet sit dolor'
}]
}],
selected: {}
})
} …Run Code Online (Sandbox Code Playgroud) 适用于我的其他路线,如“/dashboard”等,但出现在所有路线中。我基本上希望这个模板只在 url 为“/”时出现。在我的整个项目中都尝试过,只是李子不起作用。请帮忙,谢谢!!任何建议。
<template v-if="main">
<div id="accordion-nav">
<div class="accordion-panels">
<a href="/dashboard">Dashboard <i class="fa fa-caret-right" aria-hidden="true"></i></a>
</div>
<div class="accordion-panels">
<a href="/shifts">Shifts <i class="fa fa-caret-right" aria-hidden="true"></i></a>
</div>
<div class="accordion-panels">
<a href="/other">Other <i class="fa fa-caret-right" aria-hidden="true"></i></a>
</div>
</div>
</template>
<script>
export default {
name: 'accordion-nav',
computed: {
main: function () {
return this.$route.path.indexOf('/') === 0
}
}
}
</script>
<style scoped>
</style>
Run Code Online (Sandbox Code Playgroud)