javascript - _vm.myFunction 未定义,在 VueJs
问题描述
我是 VueJs 世界的新手,我对 v-on:click 函数有疑问。这是一个例子:
JS & HTML
var myNav = new Vue({
el: '#componentNav',
methods: {
currentComponentChanger: function (pageName) {
alert(pageName)
}
}
});
var myPage = new Vue({
el: '#mainComponents',
data: {
currentComponent: 'home'
}
})
<nav id="componentNav">
<ul>
<li class="active li"><a class="home active"><button v-on:click="currentComponentChanger('home')">Acceuil</button></a></li>
<li class="li"><a class="tower"><button v-on:click="currentComponentChanger('tower')">Tower Ascension</button></a></li>
<li class="li"><a class="faq"><button v-on:click="currentComponentChanger('faq')">F.A.Q.</button></a></li>
<li class="li"><a class="follow"><button v-on:click="currentComponentChanger('follow')">Nous suivre</button></a></li>
</ul>
</nav>
而不是警报,使用 currentComponentChanger() 函数,会发生错误并说“ _vm.currentComponentChanger is not defined ”。我不明白为什么,我对官方文档的例子也有同样的问题。
解决方案
推荐阅读
- visual-studio-code - VS Code 源代码控制坏了
- spring-boot - FeignException:状态 302 读取 MyService 内容:
- javascript - 如何使用 Range / GetSelection 设置边界
- tensorflow - LSTM:损失值没有改变
- c# - 分类/分类模式
- ruby-on-rails - 比较 rspec 中的 XML 文件
- python - 克隆 repo 后如何实际安装 python 依赖项
- c++ - 提升 get_io_service()
- flutter - 在 Flutter 中分配 routeNames 的最佳实践是什么?
- android - 如何有效获取 GeoFire 范围内所有用户的 OneSignal 通知密钥?