【发布时间】:2020-02-07 04:17:45
【问题描述】:
我目前正在使用 Nativescript 和 Vuejs 构建应用程序。
我使用 Material BottomNavigationBar (https://github.com/Akylas/nativescript-material-components/blob/master/packages/nativescript-material-bottomnavigationbar/README.md)。
我需要使用两种方法:
- selectTab(索引:数字)
- showBadge(index: number, value?: number)
现在我需要调用这些方法,这就是问题所在。我怎么做?
我的代码:
main.js
import BottomNavigationBar from 'nativescript-material-bottomnavigationbar/vue';
import BottomNavigationTab from 'nativescript-material-bottomnavigationbar/vue';
Vue.use(BottomNavigationBar);
Vue.use(BottomNavigationTab);
Footer.vue:
<BottomNavigationBar titleVisibility="Never" activeColor="#0285ff" inactiveColor="#5c687c"
backgroundColor="#f5f5f5" @tabSelected="onBottomNavigationTabSelected" row="1"
class="footer" ref="navBar" :selectedTab="2">
<BottomNavigationTab icon="~/assets/images/logo.png"/>
<BottomNavigationTab icon="~/assets/images/chat.png"/>
<BottomNavigationTab icon="~/assets/images/settings.png"/>
</BottomNavigationBar>
...
mounted() {
this.$refs.navBar.nativeView.selectTab(2)
}
这不起作用,并说 nativeView 未定义。
有没有办法访问这些类方法?
问候,
托比亚斯
【问题讨论】:
-
安装可能为时过早。为什么不简单地在
BottomNavigationBar上设置selectedTabIndex而不是在挂载时调用该方法。
标签: vuejs2 nativescript nativescript-vue