【发布时间】:2019-10-01 17:44:41
【问题描述】:
我有 2 个组件:
header.vue 导航.vue
在标题中我有按钮,当我单击时,在导航更改类中。但是我无法获取父组件:(如何做到这一点?
index.pug:
.g#global
frameheader
.frame
navigation(:navhidden="hiddenNav", :mobileaside="asideMobile", :links=navJson)
.frame__content
block content
main.js:
import navigation from '../vue/components/nav.vue';
import frameheader from '../vue/components/frameheader.vue';
Vue.component("navigation", navigation);
Vue.component("frameheader", frameheader);
Vue.use(VueCookie);
var global = new Vue({
el: "#global",
data() {
return {
hiddenNav: false,
asideMobile: false
}
}
})
Header.vue:
在标题中我有两个按钮,他们需要在 main.js 中更改数据 hiddenNav 和 asideMobile
<template lang="pug">
header.header
.header__left(:class="{'hidden-aside': this.$root.$emit(hiddenNav)}")
a.header__logo(href="")
img(src="img/logo_smart.png", alt="")
button.header__nav(@click="hiddenNav = !hiddenNav")
span
button.header__nav.header__nav_mobile(@click="asideMobile = !asideMobile" :class="{'active': asideMobile}")
span
</template>
<script>
import VueSlideUpDown from 'vue-slide-up-down'
export default {
name: 'frameheader',
data() {
return {
active: null,
val: false
}
},
methods: {
changeMenuType() {
this.$root.$emit(hiddenNav, true);
}
}
}
</script>
Nav.vue:
在 .frame__aside 我尝试读取来自 main.js 的父数据,但它不起作用(
<template lang="pug">
.frame__aside( :class="{'hidden-aside': navhidden, 'active': mobileaside }")
</template>
<script>
import VueSlideUpDown from 'vue-slide-up-down'
export default {
name: 'navigation',
data() {
return {
active: null,
val: false
}
},
props: {
navhidden: {
type: Boolean,
default: false
},
mobileaside: {
type: Boolean,
default: false
}
}
}
</script>
【问题讨论】:
-
请在您使用这些组件的位置显示标记(即
#globaldiv) -
谢谢,我加在上面
-
伙计,
pug的可读性太糟糕了...
标签: vue.js