有没有人能帮忙看一个 Vue.js 的问题啊?[新手]

2017-10-05 22:53:02 +08:00
 gogobody

问题就是从一个页面跳转到另一个页面之后,使用 router.go(-1),浏览器地址变了,页面不跳转

最外层 router 如下,导入了 landf:

import lanf from '@/components/LandF/router/index'

export default new Router({
    mode: 'history',
    base:base,
    routes: [
        {
            path: '/',
            name: 'PageTransition',
            component: PageTransition,
            meta: { KeepAlive: false },

            children: [
                ...lanf
            ]
        }]
})

最外层的 PageTransition 组件

<template>
    <div>
        <transition :name="transitionName">
            <keep-alive include="landf">
                <router-view  class="child-view"></router-view>
            </keep-alive>
        </transition>
    </div>
</template>

<script>
    export default {
        data () {
            return {
                transitionName: 'slide-left',
            }
        },
        beforeRouteUpdate (to, from, next) {
            if (isBack) {
                this.transitionName = 'slide-right'
            } else {
                this.transitionName = 'slide-left'
            }
            next()
        }
    }
</script>

然后是内层的 landf router:


export default [
    {
        path: '/',
        name: 'landf',
        component:index,     
    },
    {
        path:'/detail/:id',
        name:'landfitemdetail',
        component:detail,
    }

]

然后当我从 landf 点击事件跳转到 detail

this.$router.push({
	name:'landfitemdetail',
	params:{
		id:id,
		state:state
	}
	})
}

一切正常。。。。。 但是,当我从 detail 点击返回..............

goback(){
	this.$router.back(-1)
}

可以看见浏览器的地址已经改变了,然而页面并没有任何变动。。。再点击一次,就回到我的 chrome 首页了。。。。 求救啊~!!!!!!!

2496 次点击
所在节点    Vue.js
6 条回复
notes
2017-10-05 23:01:49 +08:00
额,看不出问题,也许 this.$route 用法出错
gogobody
2017-10-05 23:13:42 +08:00
@notes TT .... 好蛋疼啊
CupTools
2017-10-06 02:42:38 +08:00
PageTransititon 里面的 isBack 是哪来的时候🤷‍♀️
xiaojie668329
2017-10-06 09:01:41 +08:00
this.$router.back()就是后退,等于 this.$router.go(-1),没有 back(-1)这种写法吧。
gogobody
2017-10-06 18:49:42 +08:00
@CupTools 额,这个是我自己定义的。那个我找到原因了,我在 befrerouteleave 里面把当前组件 destroy 了,然后导致了无法 go(-1)到前一个页面,请问是啥原因呢
gogobody
2017-10-06 18:49:56 +08:00
@xiaojie668329 我在 befrerouteleave 里面把当前组件 destroy 了,然后导致了无法 go(-1)到前一个页面,请问是啥原因呢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/395576

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX