我是Nuxt/Vue的新手,对不同页面之间的数据如何工作感到困惑。我想显示一个浅色或深色的徽标,这取决于我是否在索引页面上。当在页面之间导航时,数据不会更新路线名称,因此徽标不会更改:布局页面在下方。
<template>
<main>
<img v-if="page != 'index'" src="~/assets/img/logo-white.svg">
<img v-else src="~/assets/img/logo-dark.svg">
<nuxt />
</main>
</template>
<script>
export default {
data () {
return {
page: this.$route.name
}
}
}
</script>任何帮助都是最好的。谢谢,杰米
发布于 2019-05-27 03:53:25
使用computed property而不是data,$route是反应性的,并将触发计算更新。
computed: {
page() {
return this.$route.name
}
}你也可以在你的模板中直接访问$route。
<img v-if="$route.name != 'index'" src="~/assets/img/logo-white.svg">https://stackoverflow.com/questions/56315132
复制相似问题