Vuejs2 用来完成与React相同的事情。但现在我正试图影响一个“表亲”(child->parent->other child),我采用的是1 component=1文件的方法。我不能像你那样用一个1文件=整个项目来“欺骗”给我看看你的商店!使用单文件组件这一事实不
Vuejs2 用来完成与React相同的事情。但现在我正试图影响一个“表亲”(child->parent->other child),我采用的是1 component=1文件的方法。我不能像你那样用一个1文件=整个项目来“欺骗”给我看看你的商店!使用单文件组件这一事实不,vuejs2,call,parent-child,Vuejs2,Call,Parent Child,用来完成与React相同的事情。但现在我正试图影响一个“表亲”(child->parent->other child),我采用的是1 component=1文件的方法。我不能像你那样用一个1文件=整个项目来“欺骗”给我看看你的商店!使用单文件组件这一事实不会改变任何事情。据我说,你还需要一家商店。您可以公开组件方法,查看$root、$children和$refs。但这是通往地狱的路。类似于的东西。$root.$children[1].hideTitle()将允许您调用您的方法。但是你有什么。一团
用来完成与React相同的事情。但现在我正试图影响一个“表亲”(child->parent->other child),我采用的是1 component=1文件的方法。我不能像你那样用一个1文件=整个项目来“欺骗”给我看看你的商店!使用单文件组件这一事实不会改变任何事情。据我说,你还需要一家商店。您可以公开组件方法,查看$root、$children和$refs。但这是通往地狱的路。类似于
的东西。$root.$children[1].hideTitle()
将允许您调用您的方法。但是你有什么。一团新鲜的蒸汽是什么:-)。也许你需要离开,度过一段非常糟糕的时光,然后回来创建一个商店:-)稍后再离开vuex。只需使用一个普通的javascript对象,但要确保只有一个。叫它商店,或者叫vueStore,把所有的东西都放进去。在需要的时候开始构建它,但不要在之前(树形、变异方法,然后可能是vuex)。没有存储的Vue有点像没有字符串的字符串木偶。
<template>
<div id="main">
<Header :title ="title"/>
<router-view/>
<LateralMenu/>
</div>
</template>
<script>
export default {
name: 'app'
data: function () {
return {
title: true
}
},
methods: {
hideTitle: function () {
this.title = false
console.log(this.title)
},
showTitle: function () {
this.title = true
console.log(this.title)
}
}
}
</script>
<script>
export default {
name: 'Header',
props: ['title'],
created () {
console.log(this.title)
},
methods: {
}
}
</script>
<script>
export default {
name: 'Header',
created () {
this.$on('hideTitlefinal', this.hideTitlefinal)
},
methods: {
hideTitlefinal: function () {
console.log('hideeeee')
},
showTitlefinal: function () {
console.log('shwowwww')
}
}
}
</script>
<template>
<div id="main">
<Header v-on:hideTitle="hideTitlefinal" v-on:showTitle="showTitlefinal"/>
<router-view/>
<LateralMenu/>
</div>
</template>
<script>
export default {
methods: {
hideTitle: function () {
this.$emit('hideTitle')
},
showTitle: function () {
this.$emit('showTitle')
}
}
}
</script>
Uncaught TypeError: this.$emit is not a function
at Object.showTitle (Main.vue?1785:74)
at VueComponent.showTitle (LateralMenu.vue?c2ae:113)
at boundFn (vue.esm.js?efeb:186)
at invoker (vue.esm.js?efeb:1943)
at HTMLDivElement.fn._withTask.fn._withTask (vue.esm.js?efeb:1778)