mpvue项目集成mpvue router patch插件实现路由跳转

231 阅读1分钟

github地址:github.com/F-loat/mpvu…

安装依赖

cnpm i -S mpvue-router-patch

在main.js里安装插件

import MpvueRouterPatch from 'mpvue-router-patch'

Vue.use(MpvueRouterPatch)

在页面使用

<template>
  <div>

    <div class="text">
      ibook
    </div>

    <van-button type="primary" @click="jump">按钮</van-button>


  </div>

</template>

<script>

export default {
  methods:{
    jump(){
      this.$router.push('/pages/index/main')

    }
  }

}
</script>

<style lang="scss" scoped>
.text{
  color: red;
}
</style>

至此,路由跳转插件就集成完毕了

注意 1、this.$router.push('/pages/index/main')是跳转到下个页面,不关闭当前页面。

2、this.$router.replace('/pages/index/main')是跳转到下个页面,并且关闭当前页面。