我对Vue.js非常陌生,并且使用v6-class-component的es6语法。我在尝试从孩子向父母发送活动时遇到问题。我遵循默认Vue.js语法的逻辑,但无法完成。这里有一些更多的信息:
export default class HorizontalNavigation {
handleClick (e) {
e.preventDefault();
// console.log(e.target.dataset.section);
this.$emit('ChangeView', e.target.dataset.section);
}
render (h) {
return (
<div class={ style.horizontalNavigation } >
<div class='sections-wrapper'>
<div class={ style.sections }>
<ol>
<li><a on-click={ this.handleClick } href='#1' data-section='1' class='selected'>We are</a></li>
<li><a on-click={ this.handleClick } href='#2' data-section='2'>Services</a></li>
<li><a on-click={ this.handleClick } href='#3' data-section='3'>Cases</a></li>
<li><a on-click={ this.handleClick } href='#4' data-section='4'>Studio</a></li>
<li><a on-click={ this.handleClick } href='#5' data-section='5'>Career</a></li>
<li><a on-click={ this.handleClick } href='#6' data-section='6'>Contact</a></li>
</ol>
<span class='filling-line' aria-hidden='true'></span>
</div>
</div>
</div>
);
}
}
这是孩子。我在每个li上附加一个点击,将它传递给父项。这是父母。
export default class ViewsContainer {
ChangeView (data) {
console.log(data);
}
render (h) {
return (
<div class={ style.restrictOverflow } >
<HorizontalNavigation />
<main class={ style.viewsContainer } on-ChangeView={ this.ChangeView } >
<SingleView dataSection='weare' id='1' class='selected' />
<SingleView dataSection='services' id='2' />
<SingleView dataSection='cases' id='3' />
<SingleView dataSection='studio' id='4' />
<SingleView dataSection='career' id='5' />
<SingleView dataSection='contact' id='6' />
</main>
</div>
);
}
}
继vue.js语法,我应该能够听从父儿童的事件由事件传递给元素就像一个@ChangeView但什么也没有通过组件,但道具旅行... 有什么关于这个的?谢谢 !
谢谢克雷格!但是,你怎么听父母,我不能得到任何东西...... – Lou
非常感谢Craig!我还在ChangeView侦听器上做了一个错误,而不是实例本身。所以解决我的问题是:在ViewsContainer中执行: 。 再次感谢您的时间! –
Lou