Vue Router 页面跳转:使用 this.$router.push() 方法
对于使用 Vue Router 进行页面跳转的情况,你可以使用 this.$router.push 方法来实现。请注意,this.$Router 应该修改为 this.$router。
以下是修改后的代码示例:
<template>
<view class="my-todo-list" style="height: 400rpx; align-items: center;">
<h3 class="fs">常用功能</h3>
<view class="icon-container">
<view v-for="(item, index) in icons" :key="index" class="icon-item" @tap="goPage(item.page)">
<image :src="item.icon"></image>
<text class="fu-text">{{ item.label }}</text>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
icons: [
{ icon: '/static/home/128/gongwen.png', label: '功能1' },
{ icon: '/static/home/128/gongwen.png', label: '功能2' },
{ icon: '/static/home/128/gongwen.png', label: '功能3' },
{ icon: '/static/home/128/gongwen.png', label: '功能4' },
{ icon: '/static/home/128/gongwen.png', label: '功能5' },
{ icon: '/static/home/128/gongwen.png', label: '功能6' },
{ icon: '/static/home/128/gongwen.png', label: '功能7' },
{ icon: '/static/home/128/gongwen.png', label: '全部功能', page: '/allfunction' } // 假设这里的路径是 '/allfunction'
]
};
},
methods: {
goPage(page) {
this.$router.push({ name: page });
}
}
};
</script>
<style>
/* 样式省略 */
</style>
在上述代码中,我修改了 goPage 方法,使用 this.$router.push 方法进行页面跳转。我假设 item.page 是一个命名路由的名称,通过将其传递给 this.$router.push,Vue Router 将会根据路由的配置找到相应的页面路径。
请确保你已正确配置 Vue Router,并在路由配置中为功能页面指定了正确的名称。
希望这个解释对你有所帮助!
原文地址: https://www.cveoy.top/t/topic/bQ1w 著作权归作者所有。请勿转载和采集!